与我的NSMutableArray和UITableView有一个奇怪的问题。UITableView复制所有行的第一个NSArray项目
它有数组中的4项,该表显示4行,但每行只包含第一阵列的项目,而不是第1行显示阵列第1项,第2行显示2项,等等...
这里是我的代码:
我可变数组 //在.H
NSMutableArray *tableRows;
//在.M
tableRows = [[NSMutableArray arrayWithObjects:@"For Business, For Pleasure",
@"A Great Decision",
@"Air Charter Your Honeymoon",
@"Time Flies", nil] retain];
我的表中的数据源和委托具有
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return (NSInteger)[tableRows count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"CELL_AIR";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if(cell == nil) {
cell = [self makeTableCell:cellID identifier:indexPath];
}
return cell;
}
-(UITableViewCell *)makeTableCell:(NSString *)identifier identifier:(NSIndexPath *)indexPath {
//frames
CGRect cellFrame = CGRectMake(0, 10, 320, 50);
CGRect lbl1Frame = CGRectMake(10, 0, 320, 25);
CGRect lbl2Frame = CGRectMake(10, 20, 320, 20);
UITableViewCell *cell = [[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:identifier];
UILabel *lbl1 = [[UILabel alloc] initWithFrame:lbl1Frame];
lbl1.tag=1;
lbl1.font = [UIFont systemFontOfSize:19];
lbl1.text = [tableRows objectAtIndex:indexPath.row];
UILabel *lbl2 = [[UILabel alloc] initWithFrame:lbl2Frame];
lbl2.tag=2;
lbl2.text = @"Tap to read more...";
lbl2.font = [UIFont systemFontOfSize:12];
[cell.contentView addSubview:lbl1];
[cell.contentView addSubview:lbl2];
return cell;
}
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
return 1;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50;
}
任何帮助将是巨大的感谢!
感谢
Ç
非常好。谢谢 - 将标记为已回答。 – 2010-08-15 12:40:38