Cannot retrieve member objects in TTPostController:postController method
Cannot retrieve member objects in TTPostController:postController method
I've been struggling to figure out why I'm unable to return any of my member objects when using TTPostController:postController method to send HTTP request. Here's the code I'm using.
Header:
@interface NewReplyViewController : TTPostController <TTPostControllerDelegate> {
NSString * _thread_id;
}
@property (nonatomic, assign) NSString * thread_id;
-(id)initWithThreadId:(NSString *)threadId;
@end
Implementation:
@synthesize thread_id = _thread_id;
-(id)initWithThreadId:(NSString *)threadId {
self = [super initWithNibName:nil bundle:nil];
if (self) {
self.delegate = self;
self.thread_id = threadId;
self.title = kPostReplyPhrase;
self.navigationItem.rightBarButtonItem.title = kPostPhrase;
}
return self;
}
- (void)postController:(TTPostController *)postController
didPostText:(NSString *)text
withResult:(id)result {
NSLog(@"postController:postController self.threadid = %@", self.thread_id);
}
Once I reach the NSLog part, where it tries to return the objects thread id after pressing the send button, the app crashes without much detail. The stack trace shows my _thread_id object, but I can't figure out why I'm not able to get to it. Any ideas on what I could be doing wrong?
Here are some details about the crash and the stack trace:
http://i.stack.imgur.com/NL2tD.pngThread 1, Queue : com.apple.main-thread
#0 0x01058657 in ___forwarding___ ()
#1 0x01058522 in __forwarding_prep_0___ ()
#2 0x00a99fcb in _NSDescriptionWithLocaleFunc ()
#3 0x010d0c1d in __CFStringAppendFormatCore ()
#4 0x01018507 in _CFStringCreateWithFormatAndArgumentsAux ()
#5 0x010a01ee in _CFLogvEx ()
#6 0x00b179a4 in NSLogv ()
#7 0x00b17913 in NSLog ()
#8 0x0000a7a0 in -[NewRepl开发者_开发问答yViewController postController:didPostText:withResult:] at /Users/Ken/iOS/Forums/NewReplyViewController.m:59
#9 0x00048b8f in -[TTPostController dismissAnimationDidStop] ()
#10 0x00369fb9 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] ()
#11 0x00369e4b in -[UIViewAnimationState animationDidStop:finished:] ()
#12 0x0027999b in run_animation_callbacks(double, void*) ()
#13 0x0021e651 in CA::timer_callback(__CFRunLoopTimer*, void*) ()
#14 0x010c88c3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#15 0x010c9e74 in __CFRunLoopDoTimer ()
#16 0x010262c9 in __CFRunLoopRun ()
#17 0x01025840 in CFRunLoopRunSpecific ()
#18 0x01025761 in CFRunLoopRunInMode ()
#19 0x01c2e1c4 in GSEventRunModal ()
#20 0x01c2e289 in GSEventRun ()
#21 0x00347c93 in UIApplicationMain ()
#22 0x00001fa9 in main ()
For NSString @property, always use copy:
@property (nonatomic, copy) NSString * thread_id;
AFAIK there are only two situations where you can use @property(assign):
- For literal types (i.e. non-object), for example: int, float, NSUInteger, CGPoint etc
- When you only want to have weak-reference to an object that will outlive the class object, the most common examples are delegate and view controller:
@property (nonatomic, assign) UIViewController *viewController
p/s: Weak reference prevents cyclic dependency, for example: controller retains view, then view retains controller so in the end both cannot be released
精彩评论