iphone - 使用 NSMutableArray 中的数据填充 UITableView

标签 iphone ios uitableview nsmutablearray

我想填充我的UITableView来自我的 NSMutableArray 的数据但它得到了一个异常(exception)。

异常(exception):

*** 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 中的单元格将显示 callId 中的数据, callKeyword , callNamecallNumber .

最佳答案

在你CellDetailArray数据输入 Dictionary所以您可以从 NSMutableArray 获取详细信息像贝娄:-

- (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"];

关于iphone - 使用 NSMutableArray 中的数据填充 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14994969/

相关文章:

ios - 如果 NSURLCache 满了会发生什么?

ios - undefined symbol : ___darwin_check_fd_set_overflow

ios - 如何使用 NSNumbers 在 switch 语句中设置 NSDate

ios - Offcanvas 菜单 - CSS 过渡不适用于 iphone 3 和 4

ios - 使用中国防火墙测试 ios 应用程序

iphone - 在 uiviewcontroller 中添加 uitableviewcontroller 作为 subview 时出错

ios - 我想将每个单元格链接到不同的 URL

ios - 为什么 Search Display Controller 上的 Search Bar 在 iOS 7 中没有向上移动?

ios - 滚动时如何使UITableView从下往上显示?

android - iphone 和 android 上的磁盘访问写入/更新数据的速度有多快