Iphone 如何在tableview的标签上显示nsarray的对象?
我在viewdidload上有一个NSArray好友列表,然后我有一个自定义的表视图Iphone 如何在tableview的标签上显示nsarray的对象?,iphone,objective-c,xcode,uitableview,nsarray,Iphone,Objective C,Xcode,Uitableview,Nsarray,我在viewdidload上有一个NSArray好友列表,然后我有一个自定义的表视图 每个单元格由一个标签组成,我想在表视图单元格的标签中显示数组元素 我的代码是 tableList1 = [[NSArray alloc]initWithObjects:@"Harendra",@"Satyendra",@"Jitendra",@"Sandeep",@"Dick",@"nihyan",@"alex ",@"Gorav",nil]; 及 将tableList1更改为实例变量 及 或 使用此代
每个单元格由一个标签组成,我想在表视图单元格的标签中显示数组元素 我的代码是
tableList1 = [[NSArray
alloc]initWithObjects:@"Harendra",@"Satyendra",@"Jitendra",@"Sandeep",@"Dick",@"nihyan",@"alex
",@"Gorav",nil];
及
将tableList1更改为实例变量
及
或
使用此代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//******** LableView *******
UILabel* cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,12, 141, 111)];
cellLabel.textColor=[UIColor greenColor];
cellLabel.font=[UIFont boldSystemFontOfSize:18];
cellLabel.text = [tableList1 objectAtIndex:indexPath.row];
cellLabel.backgroundColor = [UIColor clearColor];
cellLabel.opaque = NO;
[cell.contentView addSubview:cellLabel];
或
检查您在代码中添加的这两个方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableList1 count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
我希望这段代码对您有用。您在这段代码中有什么问题?我在ViewDiLoad上有一个朋友列表数组,然后我有一个自定义的表视图每个单元格都包含一个标签,我想在表视图单元格的标签中显示数组元素。那么我该怎么做呢??请建议我想在表格视图单元格的标签上显示数组元素,请注意我想在标签上而不是在单元格上显示您要打印的内容??对象的完整列表还是一个元素?请澄清您的问题..你继续说同样的话他需要在表格单元格中添加标签。cell中不是唯一的display数组元素。它正在工作并且没有显示任何错误。-cGloatTableView:UITableView*tableView heightForRowAtIndexPath:NSIndexPath*indexPath{return 50;}在这里,我想动态添加一个按钮来增加cell的高度,因此,当用户点击该按钮时,它应该增加单元格的高度,然后再次点击以调整高度。谢谢你Advance@PratapManishBhadoria选中此链接以获取create custom button@PratapManishBhadoria以获取增加高度创建全局int变量并增加该值并重新加载表格。
cell.textLabel.text =[_tableList1 objectAtIndex:indexPath.row];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//******** LableView *******
UILabel* cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,12, 141, 111)];
cellLabel.textColor=[UIColor greenColor];
cellLabel.font=[UIFont boldSystemFontOfSize:18];
cellLabel.text = [tableList1 objectAtIndex:indexPath.row];
cellLabel.backgroundColor = [UIColor clearColor];
cellLabel.opaque = NO;
[cell.contentView addSubview:cellLabel];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableList1 count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}