菜鸟UITableViewController问题
2016-12-30 22:28
232 查看
#import "TableViewController.h"
#import "SearchBar.h"
#import "TableView.h"
@interface TableViewController ()
@end
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
SearchBar *searchBar = [[SearchBar alloc] initWithFrame:CGRectMake(0, 20, 320, 30)];
searchBar.delegate = self;
TableView *tableView = [[TableView alloc] initWithFrame:CGRectMake(0, 50, 320, 430)];
tableView.delegate = self;
//tableView.backgroundColor = [UIColor blackColor];
tableView.backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 430)];
self.tableView = tableView;
[self.tableView addSubview:searchBar];
NSArray *name = @[@"Conan 1",@"Angela 2",@"Aaron 3",@"Alex 4",@"Allen 5",@"Ben 6",@"Bonnie 7",@"Camille 8",@"Carol 9",@"Caroline 10",@"Justin 11",@"Henry 12",@"Yuki 13",@"Cherry 14",@"Dide 15",@"Doris 16",@"Edio 17",@"Eissan 18",@"Flora 19",@"George 20"];
_name = name;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
return [_name count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"NameReuseable";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSLog(@"%d",indexPath.row);
cell.textLabel.text = [_name objectAtIndex:indexPath.row];
//cell.textLabel.text=[NSString stringWithFormat:@"%d",indexPath.row];
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
这是代码 当我刚运行程序的时候没问题 可是只要一上下滚动就会报错 说cell.textLabel.text = [_name objectAtIndex:indexPath.row];这里有exc_bad_access 求解啊
//cell.textLabel.text=[NSString stringWithFormat:@"%d",indexPath.row];
另外如果我换成cell.textLabel.text=[NSString stringWithFormat:@"%d",indexPath.row];这样就没有问题 上下滚动都没问题 请问是什么原因呢?
#import "SearchBar.h"
#import "TableView.h"
@interface TableViewController ()
@end
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
SearchBar *searchBar = [[SearchBar alloc] initWithFrame:CGRectMake(0, 20, 320, 30)];
searchBar.delegate = self;
TableView *tableView = [[TableView alloc] initWithFrame:CGRectMake(0, 50, 320, 430)];
tableView.delegate = self;
//tableView.backgroundColor = [UIColor blackColor];
tableView.backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 430)];
self.tableView = tableView;
[self.tableView addSubview:searchBar];
NSArray *name = @[@"Conan 1",@"Angela 2",@"Aaron 3",@"Alex 4",@"Allen 5",@"Ben 6",@"Bonnie 7",@"Camille 8",@"Carol 9",@"Caroline 10",@"Justin 11",@"Henry 12",@"Yuki 13",@"Cherry 14",@"Dide 15",@"Doris 16",@"Edio 17",@"Eissan 18",@"Flora 19",@"George 20"];
_name = name;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
return [_name count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"NameReuseable";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSLog(@"%d",indexPath.row);
cell.textLabel.text = [_name objectAtIndex:indexPath.row];
//cell.textLabel.text=[NSString stringWithFormat:@"%d",indexPath.row];
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
这是代码 当我刚运行程序的时候没问题 可是只要一上下滚动就会报错 说cell.textLabel.text = [_name objectAtIndex:indexPath.row];这里有exc_bad_access 求解啊
//cell.textLabel.text=[NSString stringWithFormat:@"%d",indexPath.row];
另外如果我换成cell.textLabel.text=[NSString stringWithFormat:@"%d",indexPath.row];这样就没有问题 上下滚动都没问题 请问是什么原因呢?
相关文章推荐
- ios开发问题2—uitableviewController中如何改变tableview的位置
- UITableViewController 滚动引起的cocos2d动画暂停问题的解决
- 解决UITableView在iOS7中UINavigationController里的顶部留白问题
- tableviewcell 自动调整textfiled的键盘遮挡问题 UITableViewController中的tableview做可以自适应键盘高度来改变tableview的额外高度。
- 解决UITableView在iOS7中UINavigationController里的顶部留白问题
- 菜鸟从这里起飞,版本控制三【自己动手,总出问题】_AX
- Help_VS2005菜鸟级问题_AX
- 菜鸟学Python(4):编码问题
- 汇编中的菜鸟问题解决方案!
- 菜鸟学Python(6):在Linux下用C扩展Python要注意的一个问题
- jsp+tomcat的配置--写给那些因为配置问题而焦虑不堪的菜鸟朋友
- 菜鸟求助—用fstream写文件时出现的问题
- 菜鸟学习C系列——遇到的第1个问题。
- 使用vs2005的GridView控件,菜鸟问题。
- ORACLE数据库菜鸟问题
- 菜鸟请教一个愚笨的问题
- 菜鸟必看--关于JDK怎样在有还原软件的机器上配置及无法使用的问题
- RHEL4 安装mysql5 遇到的问题 以及菜鸟级解决办法
- 菜鸟问题!
- 菜鸟求救!!!关于用popupmenu弹出新窗体的问题