Iphone Application:-My Application Crash(Iphone 应用程序:-我的应用程序崩溃)
问题描述
我制作了一个这样的自定义单元格类.
I make one custom cell class like this.
- (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:
中使用它,如下所示:
and use it in nextviewcontroller.m
instance method tableView:didSelectRowAtIndexPath:
like this:
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];
}
我的应用程序每次收到消息都会崩溃
my application is crashing every time with message
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 更改,这会导致您的应用崩溃.
This is because you are doing some UI changes on background thread. In ios you can not perform any UI changes on background thread , this will crash your app.
所以你必须在主线程上进行 UI 更改
So you have to do your UI changes on main thread
[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
});
这篇关于Iphone 应用程序:-我的应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Iphone 应用程序:-我的应用程序崩溃


基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01