0

このようなカスタム セル クラスを 1 つ作成します。

- (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:didSelectRowAtIndexPath:

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...
4

2 に答える 2

1

@ Rajneesh071 で述べたように、UI の変更はメイン スレッドで実行する必要があります。

これは、次を使用して実行できます。

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

または、インライン コードのセクションをメイン スレッドで実行する場合は、次のようにします。

dispatch_async(dispatch_get_main_queue(), ^{
    /* YOUR UI STUFF */
});
于 2012-12-20T11:10:01.763 に答える
0

これは、バックグラウンド スレッドで UI の変更を行っているためです。iOS では、バックグラウンド スレッドで UI の変更を実行できません。これにより、アプリがクラッシュします。

そのため、メイン スレッドで UI の変更を行う必要があります。

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

または

dispatch_async(dispatch_get_main_queue(), ^{ 
//Your Task
});

また

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // background code
});
于 2012-12-20T10:34:43.680 に答える