【发布时间】:2015-08-24 12:58:13
【问题描述】:
我以编程方式创建了一个 UITableView 并设置了它的所有属性,但我的 NSMutableArray 中的数据不会填充单元格,并且在点击时单元格不会执行任何操作。任何见解表示赞赏,谢谢!
克莱顿
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
list = [[UITableView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height * .3333, self.view.bounds.size.width, self.view.bounds.size.height * .6667) style:UITableViewStylePlain];
list.delegate = self;
list.dataSource = self;
list.backgroundColor = [UIColor magentaColor];
list.scrollEnabled = YES;
list.userInteractionEnabled = YES;
list.multipleTouchEnabled = YES;
list.hidden = NO;
[self.view addSubview:list];
[self.view bringSubviewToFront:list];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [favorites count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *Cell = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Cell];
}
cell.textLabel.text = [[global sharedInstance].favorites objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor blackColor];
cell.userInteractionEnabled = YES;
cell.hidden = NO;
cell.multipleTouchEnabled = YES;
[self.view bringSubviewToFront:cell];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"selected %ld row", (long)indexPath.row);
}
【问题讨论】:
-
是
favorites不是nil?里面有东西吗? -
@rmaddy 它改变了。它可以,但不是必须的。不管结果是否相同。
-
如果
favorites为nil或为空,则该表将没有行。很简单。当favorites有项目时,表是空的吗? -
是但不应该是,这才是重点。
-
这是什么?请说清楚。
标签: ios objective-c uitableview