__NSCFDictionary stringByDeletingPathExtension崩溃

时间:2017-01-17 09:26:38

标签: ios objective-c uitableview

我正在显示从Web服务中获取的UITableView中的数据。 在尝试在UITableView中添加此数据时,我遇到了一些奇怪的崩溃

  

由于未捕获的异常而终止应用   'NSInvalidArgumentException',原因:' - [__ NSCFDictionary   stringByDeletingPathExtension]:发送到实例的无法识别的选择器   0x7f9bc68530e0'

有谁能告诉我这是什么错误。这是我的回复

<__NSCFArray 0x7fd2846dec80>(
{
    DISTANCE = "2677.2557594500167";
    POPULARITY = 0;
    PRICE = "";
    "bar_id" = 1;
    "event_id" = "";
    "event_name" = "";
    "is_following" = 0;
    "participant_count" = 0;
    "venue_address" = “abc”;
    "venue_image" = "http://dsfdsf.com/uploads/venue_icon/original/8PHHBUbASoZZXdQNOyqL1jKAmd08rowg.jpg";
    "venue_name" = "CLUB";
},
{
    DISTANCE = "2677.2557594500167";
    POPULARITY = 0;
    PRICE = "";
    "bar_id" = 2;
    "event_id" = "";
    "event_name" = "";
    "is_following" = 0;
    "participant_count" = 0;
    "venue_address" = “def”;
    "venue_image" = "http://dsfdsf.com/uploads/venue_icon/original/8PHHBUbASoZZXdQNOyqL1jKAmd08rowg.jpg;
    "venue_name" = “Club";
}
)

这是我向UITableViewCell

添加数据的方式
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell.lbl_eventName.text = [[arrayEventData valueForKey:@"venue_name"]objectAtIndex:indexPath.row];
}

5 个答案:

答案 0 :(得分:3)

试试这个:

cell.lbl_eventName.text = [[arrayEventData objectAtIndex:indexPath.row] valueForKey:@"venue_name"];

答案 1 :(得分:1)

您可以尝试此解决方案

 NSDictionary*dict       = [Self.arrayEventData objectAtIndex:indexPath.row];
 cell.lbl_eventName.text = [dict valueForKey:@"venue_name"];

答案 2 :(得分:1)

您正在尝试访问数组中的dict值。首先来自

的Dictionary对象

[Self.arrayEventData objectAtIndex:indexPath.row]并致电

[dict valueForKey:@"venue_name"]

答案 3 :(得分:0)

您也可以使用很少的null或nil值验证来处理它。

NSString *strVanue = [[arrayEventData objectAtIndex:indexPath.row] valueForKey:@"venue_name"];

if(strVanue != nil || strVanue != (id)[NSNull null]){

   cell.lbl_eventName.text = strVanue;
}

答案 4 :(得分:0)

试试这个

NSDictionary *yourDict =[yourArray objectAtIndex:indexPath.row];
cell.lbl_eventName.text = [yourDict valueForKey:@"venue_name"];