Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone应用程序:-我的应用程序崩溃_Iphone_Objective C_Uikit_Custom Cell - Fatal编程技术网

Iphone应用程序:-我的应用程序崩溃

Iphone应用程序:-我的应用程序崩溃,iphone,objective-c,uikit,custom-cell,Iphone,Objective C,Uikit,Custom Cell,我做了一个像这样的自定义单元格类 - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { /*imgview=[[UIImageView alloc]initWithFrame:CGRectMak

我做了一个像这样的自定义单元格类

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {

    /*imgview=[[UIImageView alloc]initWithFrame:CGRectMake(10, 15, 40, 20)];
    imgview.backgroundColor = [UIColor clearColor];
    imgview.opaque = NO;*/

    Name = [[UILabel alloc]initWithFrame:CGRectMake(75, 10, 130, 30)];
    Name.backgroundColor = [UIColor clearColor];
    Name.textColor=[UIColor blueColor];
    Name.font=[UIFont fontWithName:@"Arial" size:16.0];
    Name.textAlignment=NSTextAlignmentLeft;

    CGSize textSize = [[Name text] sizeWithFont:[Name font]];
    CGFloat strikeWidth = textSize.width;
    ScreenName =[[UILabel alloc]initWithFrame:CGRectMake(strikeWidth+75.0, 25  , 150, 40)];
    ScreenName.backgroundColor = [UIColor clearColor];
    ScreenName.textColor=[UIColor redColor];
    ScreenName.font=[UIFont fontWithName:@"Arial" size:16.0];
    ScreenName.textAlignment=NSTextAlignmentLeft;

    tweetview=[[UITextView alloc]initWithFrame:CGRectMake(75, 50, 200, 70)];
    tweetview.backgroundColor = [UIColor clearColor];
    tweetview.textColor=[UIColor redColor];
    tweetview.font=[UIFont fontWithName:@"Arial" size:16.0];        
    tweetview.textAlignment=NSTextAlignmentLeft;
    tweetview.editable=NO;
    tweetview.dataDetectorTypes=UIDataDetectorTypeLink;

    Minutes=[[UILabel alloc]initWithFrame:CGRectMake(270, 20, 150, 50)];
    Minutes.backgroundColor = [UIColor clearColor];
    Minutes.textColor=[UIColor blueColor];
    Minutes.font=[UIFont fontWithName:@"Arial" size:14.0];
    Minutes.textAlignment=NSTextAlignmentLeft;

    //  [self.contentView addSubview:imgview];
    [self.contentView addSubview:Name];
    [self.contentView addSubview:ScreenName];
    [self.contentView addSubview:Minutes];

    //  [self.contentView addSubview:LastTweet];
    [self.contentView addSubview:tweetview];

}

return self;
}
并在
nextviewcontroller.m
实例方法
tableView:didselectrowatinexpath:
中使用它,如下所示:

CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
   // cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];

}
我的应用程序每次出现消息都会崩溃

Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

这是因为您正在后台线程上进行一些UI更改。 在ios中,您不能在后台线程上执行任何UI更改,这将使您的应用程序崩溃

因此,您必须在主线程上进行UI更改

[self performSelectorOnMainThread:@selector(doYourUIChanges:) withObject:nil waitUntilDone:YES];  


如@Rajneesh071所述,UI更改必须在主线程上执行

这可以通过以下方式实现:

[self performSelectorOnMainThread:@selector(doYourUIChanges:) withObject:nil waitUntilDone:YES];
或者,如果希望在主线程上执行一段内嵌代码,请使用以下命令:

dispatch_async(dispatch_get_main_queue(), ^{
    /* YOUR UI STUFF */
});

您是否正在发送任何东西(特别是tableview单元格?)是的,我正在显示用户的推文,可以在文本视图上从推文中获取。哪种类型的UI更改我的所有代码如上所述,在tableview:didSelectRowAtIndexPath方法中我使用了类似的方法。text=//从twitterOr获取,如果您喜欢基于块的方法
dispatch\u async(dispatch\u get\u main\u queue(),^{})
@iKAMBAD:那么你是如何得到这些推文的?类似于TWRequest*request=[[TWRequest alloc]initWithURL:url参数:参数requestMethod:TWRequestMethodGET];[请求performRequestWithHandler:^(NSData*responseData,NSHTTPURLRResponse*urlResponse,NSError*error){if(error!=nil){NSError*error=nil;self.dataSource=[NSJSONSerialization JSONObjectWithData:responseData选项:NSJSONReadingMutableLeaves错误:&错误];我的应用程序崩溃并在两个位置显示错误访问:一个是此处tweetview=[[UITextView alloc]init];另一个是此处cell=[[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
[self performSelectorOnMainThread:@selector(doYourUIChanges:) withObject:nil waitUntilDone:YES];
dispatch_async(dispatch_get_main_queue(), ^{
    /* YOUR UI STUFF */
});