我正在尝试加载UITableView
来自 web 服务的数据。一切正常。但是,每当UITableView
使用-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
委托方法显示记录时,我都会遇到如下异常-
这是我的代码 -
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell; //= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Reuse_Cell"];
UILabel *label = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.selectedBackgroundView = [[UIView alloc]init];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
label = [[UILabel alloc]initWithFrame:CGRectZero];
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setNumberOfLines:1];
[label setFont:[UIFont fontWithName:@"Trebuchet MS" size:18]];
[label setTag:1];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
[[cell contentView] addSubview:label];
}
if (!label)
label = (UILabel *)[cell viewWithTag:1];
[label setText:[[webserviceRecords objectAtIndex:indexPath.row] objectForKey:@"catName"]];
[label setFrame:CGRectMake(10.0, 5.0, 225.0, 35.0)];
cell.selectedBackgroundView.backgroundColor = RGBACOLOR(151.0, 191.0, 69.0, 1.0);
cell.layer.borderWidth = 2.0f;
cell.layer.borderColor = RGBCOLOR(214, 218, 1).CGColor;
return cell;
}
我的数组记录 -
自定义init
方法
- (id)initwithInteger:(NSInteger )integer
{
self = [super init];
if (self) {
startingpage = integer;
webserviceRecords = [[NSMutableArray alloc]init];
}
return self;
}
NumberofRowsInSection
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"Row count - %d", [webserviceRecords count]);
return [webserviceRecords count];
}