繁体   English   中英

使用NSMutableArray中的数据填充UITableView

[英]Populating UITableView with data from NSMutableArray

我想用来自NSMutableArray数据填充UITableView ,但是它正在出现异常。

例外:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0xa2ba880'

我的cellForRowAtIndexPath:

- (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];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    cell.textLabel.text = [callDetailArray objectAtIndex:indexPath.row];

    [cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];

    return cell;
}

这是数组:

Array: (
        {
        callId = 3;
        callKeyword = CALL100;
        callName = "Call to All";
        callNumber = 5908;
    }
)

我想发生的是UITaleView中的单元格将在callIdcallKeywordcallNamecallNumber显示数据。

在您的CellDetailArray数据Dictionary这样您就可以像Bellow这样从NSMutableArray获取Deta:-

- (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];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    NSMutableDictionary *d=(NSMutableDictionary*)[callDetailArray objectAtIndex:indexPath.row];
    cell.textLabel.text =[d valueForKey:@"callName"];

    [cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];

    return cell;
}

如果要在TableCell中显示所有四个值,则必须创建具有四个UIlable和Sate值的customeCell,例如:

YourLable1.text =[d valueForKey:@"callId"];

YourLable2.text =[d valueForKey:@"callKeyword"];

YourLable3.text =[d valueForKey:@"callName"];

YourLable4.text =[d valueForKey:@"callNumber"];

您使用以下代码

cell.textLabel.text = [[callDetailArray objectAtIndex:indexPath.row]objectForKey:@"callName" ];

您正在尝试使用访问字典而不是字符串。 callDetailArray表示字典数据。 在字典中,只有字符串可用,因此您必须使用objectForKey进行访问

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM