- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我不知道索引处的对象为什么会失败。我想知道这里是否有人知道如何纠正这个问题。失败的具体代码是 NSURL *imgURLLogo = [NSURL URLWithString:[[firstMessage objectForKey:@"message"] objectForKey:@"photo"]];
在 void load image 的底部,任何人都可以请帮我解决这个问题?
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
// Configure the cell...
NSMutableArray *arrMessages = [objectsForContacts objectForKey:[arrayOfUsers objectAtIndex:indexPath.row]];
NSMutableDictionary *firstMessage = [arrMessages objectAtIndex:0];
UILabel *lblFriendName = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 200, 20)];
lblFriendName.textAlignment = UITextAlignmentLeft;
lblFriendName.backgroundColor = [UIColor clearColor];
lblFriendName.textColor = [UIColor blackColor];
lblFriendName.font = [UIFont boldSystemFontOfSize:16.0];
lblFriendName.text = [[firstMessage objectForKey:@"message"] objectForKey:@"toname"];
[cell.contentView addSubview:lblFriendName];
UILabel *lblLastMessage = [[UILabel alloc] initWithFrame:CGRectMake(10, 25, 280, 35)];
lblLastMessage.textAlignment = UITextAlignmentLeft;
lblLastMessage.numberOfLines = 2;
lblLastMessage.backgroundColor = [UIColor clearColor];
lblLastMessage.textColor = [UIColor blackColor];
lblLastMessage.font = [UIFont systemFontOfSize:13.0];
lblLastMessage.text = [[firstMessage objectForKey:@"message"] objectForKey:@"text"];
[cell.contentView addSubview:lblLastMessage];
UILabel *lblTime = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 280, 20)];
lblTime.textAlignment = UITextAlignmentLeft;
lblTime.backgroundColor = [UIColor clearColor];
lblTime.textColor = [UIColor blackColor];
lblTime.font = [UIFont systemFontOfSize:13.0];
lblTime.text = [NSString stringWithFormat:@"%@",[[[firstMessage objectForKey:@"message"] objectForKey:@"postedat"] substringToIndex:16]];
[cell.contentView addSubview:lblTime];
cell.backgroundColor = appDelegate.pref_TableViewCellColorValue;
// cell.textLabel.text = [[dict objectForKey:@"post"] objectForKey:@"title"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSMutableDictionary *dict = [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
UIImageView *imgUser = [[UIImageView alloc] initWithFrame:CGRectMake(5, 1, 48, 48)];
if (![dict objectForKey:@"cellimage"]) {
UIImage *img = [appDelegate imageByScalingProportionallyToSize:CGSizeMake(48, 48) img:[UIImage imageNamed:@"smily.png"]];
imgUser.image = img;
NSMutableArray *arrObject = [[NSMutableArray alloc] init];
[arrObject addObject:arrMessages];
[arrObject addObject:imgUser];
[NSThread detachNewThreadSelector:@selector(loadImage:) toTarget:self withObject:arrObject];
} else {
UIImage *img = [appDelegate imageByScalingProportionallyToSize:CGSizeMake(48, 48) img:[dict objectForKey:@"cellimage"]];
imgUser.image = img;
}
[cell.contentView addSubview:imgUser];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.backgroundColor = appDelegate.pref_TableViewCellColorValue;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 80.0;
}
- (void)loadImage :(NSMutableArray *)arrObjects {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *firstMessage= [arrObjects objectAtIndex:0];
NSURL *imgURLLogo = [NSURL URLWithString:[[firstMessage objectForKey:@"message"] objectForKey:@"photo"]];
NSLog(@"%@",[[firstMessage objectForKey:@"message"] objectForKey:@"photo"]);
UIImage *imgLogo = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgURLLogo]];
if (imgLogo)
[firstMessage setObject:imgLogo forKey:@"cellimage"];
else
[firstMessage setObject:[appDelegate imageByScalingProportionallyToSize:CGSizeMake(48, 48) img:[UIImage imageNamed:@"smily.png"]] forKey:@"cellimage"];
[self performSelectorOnMainThread:@selector(loadingImageComplete:) withObject:arrObjects waitUntilDone:YES];
[pool release];
}
-(void) loadingImageComplete :(NSMutableArray *)arrayOfUsers1 {
NSMutableDictionary *dict = [arrayOfUsers1 objectAtIndex:0];
UIImageView*imgUser1 = [arrayOfUsers1 objectAtIndex:1];
UIImage *img = [appDelegate imageByScalingProportionallyToSize:CGSizeMake(48, 48) img:[dict objectForKey:@"cellimage"]];
imgUser1.image = img;
}
这是正在发生的事情的 nslog。
{
message = {
id = 20;
name = Road;
postedat = "2012-11-17 17:11:51";
status = sent;
text = "mickey d";
toname = Road;
userid = 52;
};
},
{
message = {
id = 23;
name = Road;
postedat = "2012-11-17 17:11:40";
status = sent;
text = "ok message gone wierd";
toname = Road;
userid = 52;
};
},
{
message = {
id = 17;
name = Road;
postedat = "2012-11-17 17:11:29";
status = sent;
text = my;
toname = Road;
userid = 52;
};
},
{
message = {
id = 19;
name = Road;
postedat = "2012-11-17 17:11:26";
status = sent;
text = moo;
toname = Road;
userid = 52;
};
},
{
message = {
id = 22;
name = Road;
postedat = "2012-11-17 17:11:19";
status = sent;
text = loops;
toname = Road;
userid = 52;
};
},
{
message = {
id = 21;
name = Road;
postedat = "2012-11-17 17:11:09";
status = sent;
text = ok;
toname = Road;
userid = 52;
};
},
{
message = {
id = 18;
name = Road;
postedat = "2012-11-17 17:11:05";
status = sent;
text = moo;
toname = Road;
userid = 52;
};
},
{
message = {
id = 13;
name = Road;
postedat = "2012-10-24 13:10:48";
status = sent;
text = test;
toname = Road;
userid = 52;
};
},
{
message = {
id = 16;
name = Road;
postedat = "2012-10-24 13:10:39";
status = sent;
text = hi;
toname = Road;
userid = 52;
};
},
{
message = {
id = 15;
name = Road;
postedat = "2012-10-24 13:10:36";
status = sent;
text = test;
toname = Road;
userid = 52;
};
},
{
message = {
id = 14;
name = Road;
postedat = "2012-10-24 13:10:26";
status = sent;
text = yes;
toname = Road;
userid = 52;
};
}
)
最佳答案
看起来 arrMessages 是一个 NSArray 数组。所以 arrMessages 的第一个元素是 NSArray
类型而不是 NSDictionary
。
关于iphone - NSInvalidArgumentException',原因 : '-[__NSArrayM objectForKey:]:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13440743/
我在这里撕扯我的头发。已阅读许多描述如何解决此问题的示例,但没有一个可以帮助我解决该问题。 在 UIView 上有一个链接到 IBAction 的简单按钮。 代码是这样的... 联系方式.h #imp
我在 map 中有一些注解 View ,我希望通过touchUpInside打开一个新的ViewController,但出现此错误: Terminating app due to uncaught
我想尝试一下群众的智慧……因为我现在很沮丧。提前致谢。 这是我的代码: - (void)imagePickerController:(UIImagePickerController *)ipc did
我遇到以下问题。我继承了一个应用程序,我正在尝试修改它。原始功能允许我添加带有一些文本注释的任务。我想添加一个图标以使其更具视觉吸引力。当我修改代码签名以传递图标时(实际上我只是在 NSString
[__NSArrayM relatedObjectDidChange]: unrecognized selector sent to instance error Class: NSInvalidAr
我有两个viewController,都带有一个表,应用程序可以工作,然后我在第二个viewController 中添加了导航栏,让他有机会在第一个viewController 中返回。导航栏可以工作
通常应用程序运行良好,但我在 Crashlytics 中收到问题。一周发生1-2次。适合 2k-3k 用户。应用程序适用于 iOS 7 及更高版本。报告:致命异常:NSInvalidArgumentE
此函数旨在获取 JSON 并根据作为参数发送的对象创建对象数组: + (NSArray *)Object: (id) object FromJSON:(NSData *)objectNotation
尝试将核心数据对象获取到tableview并获得Terminating app due to uncaught exception 'NSInvalidArgumentException', reas
我设计了一个应用程序,它将有一个按钮和三个标签。 当按下按钮时,将调用一个URL。 URL的JSON表示如下: [ { "_id": "50c87e8a1898044ea1458e4c",
我以编程方式实现了自动布局。 self.rightSideLine = [[UIView alloc] init]; self.rightSideLine.backgroundColor = COLO
我有一个 iOS 应用程序,可以在 Appstore 中找到。今天我测试了该应用程序,当应用程序尝试打开错误对话框时,它在我的 iPhone4 (iOS7) 上崩溃了。在 iPhone5s 上没有问题
我在其他地方使用“正常工作”的代码时遇到错误: [Error]: Caught "NSInvalidArgumentException" with reason "*** -[_NSPlacehold
我正在编写代码以向图片添加滤镜。这是代码 func applyFilter(index: Int){ print("Applying Filter....") //let contex
我正在练习创建一个主要不使用 Storyboard的 UI,当我开始调试时,我的应用程序崩溃了,并给我带来了这个错误。 我尝试从 info.plist 和目标中删除“main”,但不起作用 2019-
我有一个 tableView,我在一个单元格上创建了一个 Button。 UIButton *deleteGroupButton = [UIButton buttonWithType:UIButt
这是我的代码: @interface TabRegsViewController () @end @implementation TabRegsViewController @synthesize p
即使在这个项目之前我从未在 Objective-C 中工作过或制作过 iOS 应用程序,但我处于必须支持其他人代码的“令人敬畏”的位置,所以如果我做了一些非常明显或愚蠢的事情,请原谅. 我需要一个带有
我的代码抛出以下异常: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_
我有一个无法理解的问题,我正在使用一个用于使用Map Open Source Map(https://github.com/route-me/route-me)的库,该示例运行完美,并且我相信不是与代
我是一名优秀的程序员,十分优秀!