Iphone 将NSarray项插入指定的UItableviewcell
我有一个包含10个单元格的UItableview。我需要在此tableview中显示一条来自NSarray的消息。该数组包含3项,需要在3个单元格中的任意一个单元格中显示Iphone 将NSarray项插入指定的UItableviewcell,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我有一个包含10个单元格的UItableview。我需要在此tableview中显示一条来自NSarray的消息。该数组包含3项,需要在3个单元格中的任意一个单元格中显示 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; Custom
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomTableView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ CustomTableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSString *order = [orderArray objectAtIndex:indexPath.row];
NSString *sdate = [dateArray objectAtIndex:indexPath.row];
//Label positions
UILabel *ordernum = [[UILabel alloc] initWithFrame:CGRectMake(5,28,95,21)];
UILabel *date = [[UILabel alloc] initWithFrame:CGRectMake(100,28,80,21)];
UILabel *orderStatusMessage = [[UILabel alloc] initWithFrame:CGRectMake(200,28,80,21)];
NSString *ordertypeName = [ordertypeArray objectAtIndex:indexPath.row];
ordernum.textColor = [UIColor blackColor];
[cell.contentView addSubview:ordernum];
date.textColor = [UIColor blackColor];
[cell.contentView addSubview:date];
orderStatusMessage.textColor = [UIColor blackColor];
if ([ordertypeName isEqualToString:@"saved"]) {
ordernum.text = [NSString stringWithString:@"Saved Order"];
date.text = [NSString stringWithFormat:@"%@",sdate];
}
else{
if (![order isEqualToString:@""]) {
for (int i=0; i<[reversed count]; i++)
{
stat=[reversed objectAtIndex:i];
}
}
ordernum.text = [NSString stringWithFormat:@"%@",order];
date.text = [NSString stringWithFormat:@"%@",sdate];
orderStatusMessage.text =[NSString stringWithFormat:@"%@",stat];
[cell.contentView addSubview:orderStatusMessage];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
// }
return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
CustomTableView*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[CustomTableView alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:nil];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
NSString*order=[orderArray objectAtIndex:indexPath.row];
NSString*sdate=[dateArray objectAtIndex:indexPath.row];
//标签位置
UILabel*ordernum=[[UILabel alloc]initWithFrame:CGRectMake(5,28,95,21)];
UILabel*date=[[UILabel alloc]initWithFrame:CGRectMake(100,28,80,21)];
UILabel*orderStatusMessage=[[UILabel alloc]initWithFrame:CGRectMake(200,28,80,21)];
NSString*ordertypeName=[ordertypeArray objectAtIndex:indexPath.row];
ordernum.textColor=[UIColor blackColor];
[cell.contentView addSubview:ordernum];
date.textColor=[UIColor blackColor];
[cell.contentView addSubview:date];
orderStatusMessage.textColor=[UIColor blackColor];
如果([ordertypeName IsequalString:@“已保存”]){
ordernum.text=[nsstringwithstring:@“保存的订单”];
date.text=[NSString stringWithFormat:@“%@”,sdate];
}
否则{
如果(![order isEqualToString:@“”){
对于(int i=0;i开始,您的for循环是假的
if (![order isEqualToString:@""]) {
for (int i=0; i<[reversed count]; i++)
{
stat=[reversed objectAtIndex:i];
}
}
if(![order IsequalString:@”“){
对于(int i=0;我无法理解您的逻辑,您能否将程序缩进到您为表创建的行数中。numberofrowsInsection方法计数。问题:您所说的反向数组是什么意思?…注释:您使用的是dequeueReusableCellWithIdentifier
,并且每次该单元格出列时,您都会添加一个新的标签disrE根据已添加到其中的标签。UILabel alloc/init应位于您alloc/init单元格并添加到contentView的同一位置。如果您使用的是故事板,则应在IB中添加它们并访问它们,每次单元格出列时,将alloc/init/add as子视图安装到contentView。