- (void)fetchLastMessageInChannel
{ __weak id weakSelf = self;
for (ANKChannel *channel in self.channelArray)
{
NSLog(@"channels %@",channel);
NSLog(@"channel last message %@",channel.latestMessageID);
[[ClientManager currentClient] fetchMessageWithID:channel.latestMessageID inChannel:channel
completion:^(id responseObject, ANKAPIResponseMeta *meta, NSError *error)
{
NSLog(@"message object %@",responseObject);
ANKMessage *message = responseObject;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf populateTextViews:message.text];
});
NSLog(@"message text %@",message.text);
}];
}
}
-(void)populateTextViews:(NSString *)message {
NSMutableArray *textViews = [@[] mutableCopy];
NSMutableAttributedString *postText = [[NSMutableAttributedString alloc] initWithString:message];
[postText addAttributes:@{
NSFontAttributeName : [UIFont preferredFontForTextStyle:UIFontTextStyleBody],
NSForegroundColorAttributeName : [UIColor darkTextColor]
}
range:NSMakeRange(0, postText.length)];
UITextView *postTextView = [[UITextView alloc] initWithFrame:CGRectMake(80, 30, kPostLabelMaxWidth, 44)];
postTextView.attributedText = postText;
postTextView.dataDetectorTypes = UIDataDetectorTypeAll;
postTextView.backgroundColor = [UIColor whiteColor];
postTextView.editable = NO;
postTextView.scrollEnabled = NO;
postTextView.clipsToBounds = NO; // So it doesn't clip the text selector
CGRect textViewBounds = postTextView.bounds;
textViewBounds.origin = CGPointMake(80, 30);
textViewBounds.size.width = MAX(textViewBounds.size.width, kPostLabelMaxWidth);
textViewBounds.size.height = postTextView.contentSize.height;
postTextView.bounds = textViewBounds;
[postTextView sizeToFit]; // Reload the content size
[textViews addObject:postTextView];
self.channelTextViewArray = [textViews copy];
}
在我得到的帮助下,就我的方法而言,这就是我现在的立场。self.channelTextViewArray 返回 nil 并导致崩溃,因为 populateTextViews(NSString*) 消息永远不会被调用。
有任何想法吗?