我在这里遇到了 UI_USER_INTERFACE_IDIOM() 的问题
- (void)viewDidLoad
{
[super viewDidLoad];
self.footerCommentActivity = self.commentActivity;
self.footerNewsActivity = self.newsActivity;
[self.otherNews setTableFooterView:nil];
[self.commentTableView setTableFooterView:nil];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
html = [NSString stringWithFormat:@"<html style='-webkit-text-size-adjust: none;'><head><style>p {margin:0px 0px 10px;padding:0;}</style></head><body style='background-color:transparent;padding:0;margin:0;'>%@</body></html>", self.postContentText];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
html = [NSString stringWithFormat:@"<html style='-webkit-text-size-adjust: none;'><head><style>p {margin:0px 0px 10px;padding:0;}</style></head><body style='background-color:transparent;padding:0;margin:0;-webkit-column-count:2;'>%@</body></html>", self.postContentText];
}
[self.postContent loadHTMLString:html baseURL:nil];
self.loadMoreComments = false;
self.loadMoreNews = false;
}
更新代码 2:我已将代码更改为 viewDidAppear 函数,但它仍然崩溃
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
sharedData = [NSUserDefaults standardUserDefaults];
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:self.otherNewsArray];
for (int i =0; i < tempArray.count; i++) {
Post *otherNewsPost = [tempArray objectAtIndex:i];
if (otherNewsPost.postID == self.postID) {
[tempArray removeObjectAtIndex:i];
break;
}
}
self.otherNewsArrayWithoutCurrentPost = [tempArray copy];
//update height of main image, text, video.
NSLog(@"post image: %@",self.postImageName);
if (self.postImageName == nil) {
self.postImage.image = nil;
CGRect imageFrame = self.postImage.frame;
imageFrame.size.height = 0.0f;
self.postImage.frame = imageFrame;
CGRect f = self.postContent.frame;
f.origin.x = 0; // new x
f.origin.y = 0; // new y
self.postContent.frame = f;
} else {
[self.postImage setImageWithURL:[NSURL URLWithString:self.postImageName]
placeholderImage:[UIImage imageNamed:@"postimage-placeholder"]];
// self.postImage.image = [UIImage imageNamed:self.postImageName];
}
NSString *htmlString = @"";
if (self.columns == false) {
htmlString = [NSString stringWithFormat:@"<html style='-webkit-text-size-adjust: none;'><head><style>p {margin:0px 0px 10px;padding:0;}</style></head><body style='background-color:transparent;padding:0;margin:0;'>%@</body></html>", self.postContentText];
[self.postContent loadHTMLString:htmlString baseURL:nil];
} else {
htmlString = [NSString stringWithFormat:@"<html style='-webkit-text-size-adjust: none;'><head><style>p {margin:0px 0px 10px;padding:0;}</style></head><body style='background-color:transparent;padding:0;margin:0;-webkit-column-count:2;'>%@</body></html>", self.postContentText];
[self.postContent loadHTMLString:htmlString baseURL:nil];
}
[self.commentTableView reloadData];
[self.otherNews reloadData];
if (self.otherNews.hidden) {
[self adjustViewHeightForTable:self.commentTableView];
} else {
[self adjustViewHeightForTable:self.otherNews];
}
[self markAsRead];
[self loadPost];
}
当我的应用程序启动并开始使用应用程序登录时,它崩溃了我在这里使用 ipad 模拟器
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Session status]: unrecognized selector sent to instance 0x8889890'
*** First throw call stack: