unit test local objects or dependency injection with OCMock? - ios

Trying to create simple test for following function:
-(void)presentWithString:(NSString *)name
{
CustomVC *customVC = [[CustomVC alloc] initWithName:name];
UINavigationController *nav = [[UINavigationController alloc] init];
nav.viewControllers = #[customVC];
dispatch_async(dispatch_get_main_queue(), ^{
[self.vc presentViewController:nav animated:YES completion:nil];
});
}
I can split this into chunks with dependency injection, but don't know how to write proper test either way. What would be the best practice for this example?

What do you want to test? There are 3 things happening in your method :
CustomVC is created with name passed.
CustomVC is embedded inside navigation controller.
The navigation controller is presented on self.vc.
You can write a test that checks the whole flow :
- (void)testPresentWithString_shouldPresentCustomVC_withPassedName {
// Arrange
NSString *expectedName = #”name”;
XCTestExpectation *exp = [self expectationWothDescription:#”presentVC called”];
TestClass *sut = [[TestClass alloc] init];
id vcMock = OCMClassMock([UIViewController class]);
sut.vc = vcMock;
OCMExpect([vcMock presentViewController:OCM_ANY animated:YES completion:nil]).andDo(^(NSInvocation *invocation) {
UINavigationController *nav = nil;
[invocation getArgument:&nav atIndex:2];
CustomVC *custom = nav.viewControllers.firstObject;
// Assert
XCTAssertNotNil(nav);
XCTAssertTrue([nav isKindOfClass:[UINavigationController class]]);
XCTAssertEqual(nav.viewControllers.count, 1);
XCTAssertNotNil(custom);
XCTAssertTrue([custom isKindOfClass:[CustomVC class]]);
XCTAssertEqual(custom.name, expectedName);
[exp fulfill];
});
// Act
[sut presentWithString:expectedName];
// Assert
[self waitForExpectationsWithTimeout:1 handler:nil];
OCMVerifyAll(vcMock);
// Cleanup
[vcMock stopMocking];
}
This code checks everything that happens in your method - that a method got called with specific arguments, that the first of these arguments was a navigation controller with only CustomVC embedded and that this CustomVC had name set. Obviously I’ve made assumptions that vc property on tested class can be set from outside and that the name on CustomVC can be read. If not, it may be trickier to test some parts of this.
Personally I wouldn’t unit test this. I would test the initialization of CustomVC separately, and put the whole presentation under a UI test.
Let me know if everything is clear!
—
Side note : I wrote this on mobile from memory, so there might be small mistakes in the code. I will update it when I have a chance to check it with Xcode.

Related

Making SMS ViewController pop up on iPhone using Unity3D

I am having trouble getting MFMessageCompose to work with Unity3D iOS Plugin.
I got an alert window to pop up with buttons but I am having an error when accessing the MFMessageComposer. Can't seem to get the method to pop up the window properly.
Here is my iOSBridge.h (linked file if you want):
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <MessageUI/MessageUI.h>
#interface Delegate : NSObject <UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate>
#end
And my iOSBridge.mm file:
#import "iOSBridge.h"
#implementation Delegate
//Trying to still understand the meaning behind this line. Why???
-(id)init
{
return self;
}
//RATE US Button Numbers
//Not entirely sure What I did here but it still bring it up. This section has nothing to do with SMS
-(void) alertView: (UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//Give back the number of the button
NSString *inStr = [NSString stringWithFormat:#"%d", (int)buttonIndex];
const char *cString = [inStr cStringUsingEncoding:NSASCIIStringEncoding];
UnitySendMessage("Popup", "UserFeedBack", cString);
NSLog(#"%li", (long)buttonIndex);
} // RATE US button number end
-(void)SMS:(id)sender{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
[controller setMessageComposeDelegate:self];
if([MFMessageComposeViewController canSendText]){
[controller setRecipients:[NSArray arrayWithObjects:nil]];
[controller setBody:[NSString stringWithFormat:#"Text"]];
//WHYYY do you not work
//[self presentViewController:controller animated:YES];
Delegate *appDelegate = UIApplication.sharedApplication.delegate;
[appDelegate.window.rootViewController presentViewController:controller animated:YES completion:nil]
}
}
#end
static Delegate* delegateObject;
extern "C"
{
//A method for unity can run
void _AddNotification(const char* title,
const char* body,
const char* cancelLabel,
const char* firstLabel,
const char* secondLabel)
{
//Don't have a full grasp of this delegateObject thing yet.
if(delegateObject ==nil){
delegateObject = [[Delegate alloc]init];
}
//iOS Alert Pop up view RATE OUR GAME
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: [NSString stringWithUTF8String:title]
message:[NSString stringWithUTF8String:body] delegate:delegateObject
cancelButtonTitle:[NSString stringWithUTF8String:cancelLabel]
otherButtonTitles:[NSString stringWithUTF8String:firstLabel],[NSString stringWithUTF8String:secondLabel], nil];
[alert show];
} //End of _AddNotification
//SMS Method for Unity to use
void _SMSGO(const char* Mbody){
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
NSString *s = [NSString stringWithFormat:#"%s", Mbody];
controller.body = s;
//Suppose to Brings up the SMS view not sure why it isnt working or how to make this work
//If this can work its major progress
[delegateObject presentViewController:controller animated:YES];
}
}
}
So these:
-(void) alertView: (UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *inStr = [NSString stringWithFormat:#"%d", (int)buttonIndex];
const char *cString = [inStr cStringUsingEncoding:NSASCIIStringEncoding];
UnitySendMessage("Popup", "UserFeedBack", cString);
NSLog(#"%li", (long)buttonIndex);
}
-(void)SMS:(id)sender{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
[controller setMessageComposeDelegate:self];
if([MFMessageComposeViewController canSendText]){
[controller setRecipients:[NSArray arrayWithObjects:nil]];
[controller setBody:[NSString stringWithFormat:#"Text"]];
//WHYYY do you not work
//[self presentViewController:controller animated:YES];
Delegate *appDelegate = UIApplication.sharedApplication.delegate;
[appDelegate.window.rootViewController presentViewController:controller animated:YES completion:nil]
}
}
Code blocks are actually not being accessed at all through your bridge. So nothing in this will be touched at all.
The - (id) init is the initializer of the class. So in order to access anything in that file from anything else, you have to init it first. An easier way to think of this is:
extern.c is a separate file.
static Delegate *delObj;
extern "C"
{
void _callMain (const char *hello) {
/**
* delObj is a static so it "Will be once it is" so it will be
* in memory (mallocated) the moment you tell it to be something.
*/
if (!delObj) {
In this case, we want that static object to be an instance of Delegate (not a particularly good name to set your class to, it will lead to much confusion). We "start" or initialize this class by calling init and we tell it this is an object we need, chuck it on the heap read this.
delObj = [[Delegate alloc] init];
}
// Now we can call the function in the next file
[delObj helloWorld];
}
Delegate.m - Think of this as a different file. You can access this file from extern.c because (in reality) it's just included in the same file. But this of this as a separate entity entirely. You have to access this "file" from extern.c
#implementation Delegate
// This is the function we call with [[Delegate alloc] init];
-(id) init {
// It simply returns itself - saying hey this is the object memory chunk in the heap you want to talk to.
return self;
}
// This is the function we call with [delObj helloWorld];
- (void) helloWorld {
NSLog("Hello World"); // This will show up in your console.
}
So the above code has two functions, one that says "this is the memory object your looking for" - one that says "I'm a function, lets execute something".
Now with all that laid out, you're not calling:
-(void) alertView: (UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
OR
-(void)SMS:(id)sender{
Via your extern "C". The reason why _AddNotification works is because you have code in there calling UIAlertView AFTER making sure your delegateObject is in memory. In you _SMSGO function, you're not putting your object into memory. So when you call delegateObject in [delegateObject presentViewController:controller animated:YES]; it says "Oh I know what delegateObject is but it's equal to nothing. In fact it does not have memory to execute anything!" Thats why you probably don't get any errors or exceptions. The code knows there is a static object, but it hasn't been set to anything yet.
SOLUTION:
First, void methods don't need :(id)sender thats more of a IBAction thing unless you actually want to send something - so change -(void)SMS:(id)sender{ to - (void) SMS { (with the pretty spacing, too. It's mo' better for eyes).
Second, swap everything in SMS with:
- (void) SMS {
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
[controller setMessageComposeDelegate:self];
if([MFMessageComposeViewController canSendText]){
[controller setRecipients:[NSArray arrayWithObjects:nil]];
[controller setBody:[NSString stringWithFormat:#"Text"]];
// We now know why we work!
[self presentViewController:controller animated:YES];
}
}
But WAIT! And do not copy and paste. Be sure to understand each line of code you write.
This line allocates an object into memory, in this instance, the MFMessageComposeViewController object. Then initializes it.
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
This line sets the delegate of the object we just made (controller). But why can it do this? Because we have MFMessageComposeViewControllerDelegate set in the iOSBridge.h file. This tells everything in your .mm file "hey if we happen to have a MFMessage object somewhere, it may access delegate properties if you want."
[controller setMessageComposeDelegate:self];
if ( [MFMessageComposeViewController canSendText] ) is human readable.
Same with [controller setRecipients:[NSArray arrayWithObjects:nil]]; and [controller setBody:[NSString stringWithFormat:#"Text"]];
But now [self presentViewController:controller animated:YES]; is were we need to dive in.
So in Unity, they said "hey, we don't need to deal with every single possible native function being called" - so they created access to the extern capability for you. This allows you to talk to Objective-C from the UnityScript side of things. Objective-C is just a superset of C, so thats common ground. Everything in here should ONLY call functions in Delegate. The example of this is above in the fake extern.c code block. The only thing that is doing is creating delegateObject and calling a function. Now for the next step. Swap everything in _SMSGO with:
void _SMSGO (const char *mBody) { // I prefer char *name vs char* name but it doesn't matter
[delegateObject SMS]; // add mBody as a parameter when you're ready. Handle the stringWithUTF8String on the Objective-C side of things. Yes, this is not the Obj-C side, this is the C side.
}
"But wait... you just delegateObject needs to be a thing" - Yes it does. Create another method in your extern "C" section called _init and run this one time from Unity in the Awake or Start function of your class. This will set your static object one time and never mess with it again. Simply make it:
void _init() {
if ( !delegateObject ) {
delegateObject = [[Delegate alloc] init];
}
}
!delegateObject is the same thing as delegateObject == nil but cleaner code. Both say "We don't know what dat is" - Ok now we have our delegateObject, we are free to make our next calls with delegateObject as much as we'd like.
Now when you call [delegateObject SMS] it goes to - (void) SMS. And when you call self presentViewController it knows that self is referring to an iOS Native Object. If you call presentViewController in extern "C" it says "... um, hmm. I haven't got the foggiest notion what that means" - for this reason, we have use everything in your extern "C" section as a crossover to your Delegate object. That is the whole purpose of the extern thing, just to call things in your Obj-C stuff.
Hope this helps.

OCMock - "Unexpected Method Invoked" although stubbed

Here is the testing code:
id dataControllerMock = [OCMockObject mockForClass:[RAMImsakyaDataController class]];
[[[dataControllerMock expect] andReturn:dataControllerMock] alloc];
(void)[[[dataControllerMock expect] andReturn:dataControllerMock] init];
[[[dataControllerMock stub] andReturn:#"30.06 , 50.67"] getLocationTitle];
[self.viewController viewDidLoad];
XCTAssertTrue([self.viewController.title isEqualToString:#"30.06 , 50.67"], #"View controller title is wrong");
[dataControllerMock verify];
The problem is that the dataControllerMock causing a failure with "unexpected method invoked: getLocationTitle"! I do stub the method. And even if I change the stub to expect, same thing. When I breakpoint inside viewDidLoad, the mock is already there as expected yet it doesn't recognize the getLocationTitle method.
Update: here is the viewDidLoad code
NSString *location = [self.dataController getLocationTitle];
if (location == nil) {
self.title = #"إمساكية رمضان ١٤٣٥ هـ";
} else {
self.title = [NSString stringWithFormat:#"إمساكية رمضان ١٤٣٥ هـ (توقيت %#)", location];
}
Why not take a different approach and use a partial mock?
RAMImsakyaDataController* realObject = [RAMImsakyaDataController new];
id partialObject = [OCMockObject partialMockForObject:realObject];
[[[partialObject stub] andReturn:#"30.06 , 50.67"] getLocationTitle];
[partialObject viewDidLoad]; // Method under test
XCTAssertTrue([partialObject.title isEqualToString:#"30.06 , 50.67"], #"View controller title is wrong");
I find that trying to mock alloc can lead to difficult behavior.
EDIT
// In MyViewController
- (RAMImsakyaDataController*)dataController {
if (!_dataController) {
_dataController = [[RAMImsakyaDataController alloc] init];
}
return _dataController;
}
Then partial mock the VC and replace this method with one that returns your partially mocked data controller.
My guess is that OCMock is failing to correctly mock the data controller's +alloc method so your view controller is using a real data controller instead of a mock.
I've had a difficult time mocking object creation. What I've ended up doing instead of trying to mock +alloc is putting testability stubs on the objects I want to test that create their dependencies, and then I can use a partial mock of the object under test to override the object creation. Like:
#implementation ViewController
- (void)init {
...
_dataController = [self newDataController];
...
}
- (DataController *)newDataController {
return [[DataController alloc] init];
}
#end
And then in my test
ViewController *underTest = [ViewController alloc];
id mockUnderTest = [OCMockObject partialMockForObject:underTest];
id mockDataController = [OCMockObject niceMockForClass:[DataController class]];
[[[mockUnderTest stub] andReturn:[mockDataController retain]] newDataController];
underTest = [underTest init];

Objective-C Passing NSURL to another viewcontroller

I have two view controllers: FirstViewController and SecondViewController. The project is to record a video and attach it to an email. I can record it and have it able to email, I just need to attach it. I am able to get a URL for the video in FirstViewController, but passing it isn't working.
FirstViewController -
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.movie"])
{
// Saving the video to phone / // Get the new unique filename
NSString *sourcePath = [[info objectForKey:#"UIImagePickerControllerMediaURL"]relativePath];
UISaveVideoAtPathToSavedPhotosAlbum(sourcePath, self, /*#selector(video:didFinishSavingWithError:contextInfo:)*/nil, nil);
self.movieURL= [[NSURL alloc] initFileURLWithPath: sourcePath];
NSLog(#"movieURL");
NSLog(self.movieURL.absoluteString);
SecondViewController *sendMovie = [[SecondViewController alloc] initWithNibName:#"ViewController" bundle:nil];
sendMovie.movieU = [[NSURL alloc] initFileURLWithPath: sourcePath];
[[self navigationController] pushViewController:sendMovie animated:YES];
NSLog(#"movieU");
NSLog(sendMovie.movieU.absoluteString);
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
SecondViewController to attach to email -
NSLog(#"1st print");
NSLog(self.movieU);
[controller addAttachmentData:[NSData dataWithContentsOfURL:self.movieU] mimeType:#"video/MOV" fileName:#"defectVideo.MOV"];
NSLog(#"2nd print");
NSLog(self.movieU.absoluteURL);
[self presentViewController:controller animated:YES completion:nil];
SecondViewController.h property of NSURL
#property(nonatomic) NSURL *movieU;
The movieURL is a property in the FirstViewController, but I don't believe is needed.
I can see the URL in the FirstVC, but it appears nil in the SecondVC.
Solutions -
1) define NSURL *movieU as a extern instead of property.
2) else define it as a property of AppDelegate and access it.
3) or else synthesize property movieU and do allocate like -
in your FirstViewController -
SecondViewController *sendMovie = [[SecondViewController alloc] initWithNibName:#"ViewController" bundle:nil];
NSURL *url = [[NSURL alloc] initFileURLWithPath: sourcePath];
sendMovie.movieU = url;
[[self navigationController] pushViewController:sendMovie animated:YES];
And NSLog it in your SecondViewController.
Hope this helps!
There is nothing wrong with the way you are going about passing information. Try this:
// In you code where you create the second view controller.
SecondViewController *sendMovie = [[SecondViewController alloc] initWithNibName:#"ViewController" bundle:nil];
// SecondViewController viewDidLoad method being called (movieU is still nil)
sendMovie.movieU = [[NSURL alloc] initFileURLWithPath: sourcePath];
// Do a nil test here
if (!sendMovie.movieU) {
NSLog(#"%#",#"It's nil here!"); // If this is the case something is wrong with "sourcePath"
} else {
NSLog(#"%#",#"It's not nil here!");
}
[[self navigationController] pushViewController:sendMovie animated:YES];
// SecondViewController viewWillAppear method being called (movieU is NOT nil)
// SecondViewController viewDidAppear method being called (movieU is NOT nil)
This test will tell you a lot. If its nil here then the problem is not with setting the second view controller's property but with actually creating the NSURL object. It could be a lot of things like you are overwriting it somewhere in the second view controller (e.g. viewWillAppear method). Just follow the trail using break points, logging, etc. to follow its life time.
Edit - Debugging Procedure
Set break points where you create Second VC, set its property, push it, and finally view it (clicking on the tab). Set break points throughout the lifecycle of the second VC (viewDidLoad, viewWillAppear, viewDidAppear, etc). This will allow you to step through the entire lifecycle of your VC. If you haven't utilized those methods go ahead and define them anyway including a call to super. As you step through these break points keep checking the value of movieU. You will see it is nil at first, then you set it (we know this from your comments), its not nil, then it becomes nil, again, etc. If you are patient and systematic you will find it and learn a whole lot about the lifecycle of VCs. If you don't systematically step through you may miss something. For instance maybe your code is creating a whole new Second VC when you click on the tab to actually look at it. Stepping through your code this way will show that.
Edit
Make sure you are testing in the viewWillAppear/viewDidAppear methods or later so that the property has actually been set. See comments in my code.
Edit
A property of retainable object pointer type which is synthesized without a source of ownership has the ownership of its associated instance variable, if it already exists; otherwise, [beginning Apple 3.1, LLVM 3.1] its ownership is implicitly strong. Prior to this revision, it was ill-formed to synthesize such a property.
From: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#property-declarations
According to this (unless you are specifying weak on the ivar - unlikely) it should be strong by default.
Good luck.
use this
self.movieURL = [NSURL fileURLWithPath:sourcePath];
instead of
self.movieURL= [[NSURL alloc] initFileURLWithPath: sourcePath];
hope this work
I got it fixed! I decided to use a singleton which uses a shared instance through another class. I created a whole new class called Singleton and only contained the sharedinstance method:
+ (id)sharedInstance {
static id sharedInstance = nil;
if (sharedInstance == nil) {
sharedInstance = [[self alloc] init];
}
return sharedInstance;
}
Singleton.h
#property NSURL *movieU;
+ (id)sharedInstance;
Make sure to import the singleton class to both First and Second VC.
SecondVC.m
Singleton* single = [Singleton sharedInstance];
[controller addAttachmentData:[NSData dataWithContentsOfURL: single.movieU] mimeType:#"video/MOV" fileName:#"defectVideo.MOV"];
FirstVC.m
Singleton* single = [Singleton sharedInstance];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.movie"]){
// Saving the video / // Get the new unique filename
NSString *sourcePath = [[info objectForKey:#"UIImagePickerControllerMediaURL"]relativePath];
UISaveVideoAtPathToSavedPhotosAlbum(sourcePath, self, /*#selector(video:didFinishSavingWithError:contextInfo:)*/nil, nil);
self.movieURL = [[NSURL alloc] initFileURLWithPath: sourcePath];
NSLog(#"movieURL");
single.movieU = self.movieURL;
By doing this, it successfully would pass the url containing the information for the recorded video to be attached to the email.

Adding a root view controller OCMockObject[UIViewController] as a child view controller error

I've been working on my unit tests for iOS programming, and I've run into a little problem when trying to validate my main class by mocking it's child classes using OCMock and then seeing if the main class adds the child controllers (mockObjects[uiviewContoller]) and then verifying that an object calls a method on each of the child controllers.
The problem is I keep getting a "test failed 'adding a root view controller OCMockObject[UiViewController] as a child of view controller'"
every other time i run the test.
- (void)setUp
{
[super setUp];
testMain = [[UIViewController alloc] init];
}
- (void)tearDown
{
for (UIViewController *testCon in testMain.childViewControllers) {
[testCon removeFromParentViewController];
}
testMain = nil;
[super tearDown];
}
test:
- (void) testDayNightTriggerTriggersAllSubviews{
id mockTopController = [OCMockObject niceMockForClass:[UIViewController class]];
id mockBottomController = [OCMockObject niceMockForClass:[UIViewController class]];
id mockMainScreen = [OCMockObject niceMockForClass:[UIViewController class]];
[[mockTopController expect] dayNightTrigger];
[[mockBottomController expect] dayNightTrigger];
[[mockMainScreen expect] dayNightTrigger];
//trigger
[testMain dayNightTrigger:mockTopController bottom:mockBottomController main:mockMainScreen];
[mockBottomController verify];
[mockTopController verify];
[mockMainScreen verify];
}
Method to verify:
//overload
- (void) dayNightTrigger:(UIViewController *) top bottom:(UIViewController *)bottom main:(UIViewController *)main{
self.bottomMenu = bottom;
self.topMenu = top;
self.mainScreen = main;
[self dayNightTrigger];
}
- (void) dayNightTrigger{
[self.app dayNightTrigger];
[self.bottomMenu dayNightTrigger];
[self.topMenu dayNightTrigger];
[self.mainScreen dayNightTrigger];
}
I was wondering if there is anything wrong with my setup/teardown? or I'm doing something wrong with the OCMock framework, but really as to why I keep getting this error.
I've run into the same issue. I'm guessing that your properties bottomMenu, topMenu, and mainScreen set bottom, top, and main as child view controllers of the other view controller.
Unfortunately, addChildViewController: looks at some value in the UIViewController* structure. Since it's a direct memory access and not a method call, the OCMockObject can't intercept it. As a result, the mock object is (sometimes) treated as being a root view.
The way I found around it was to override addChildViewController: on the object I was testing in the test file and have it do nothing:
#implementation MyViewController (overwriteForTesting)
- (void)addChildViewController:(UIViewController *)childController {
}
#end
This means that it won't add the view controller to its list of children though.

Under ARC, keep getting EXC_BAD_ACCESS after using ARC, because of using Block?

Issue:
I keep getting EXC_BAD_ACCESS. And after I open NSZombieEnabled, I saw this [FeatureCommentListViewController respondsToSelector:]: message sent to deallocated instance 0x7c1dc30
Before I changed my project to ARC, there is no such error, but after I changed to ARC, this error appeared.
I declare a ViewController in a Block and push it into navigation Controller. Will this reason case it's lifetime shorter?
UIBlockButton is from this post
UIBlockButton *lbGood3 = [[UIBlockButton alloc] initWithFrame:CGRectMake(0, 0, First_Button_Width, [self getGoodRow2Height:productDetail]) ];
[lbGood3 handleControlEvent:UIControlEventTouchUpInside withBlock:^ {
NSLog(#"%#", Label.text);
ProductDetail *productDetail = [productDetailDict objectForKey:#"product"];
NSString *dp_id = [NSString stringWithFormat:#"%#-%#",productDetail.url_crc,productDetail.site_id];
FeatureCommentListViewController *cmtListController = [[FeatureCommentListViewController alloc] initWithNibName:#"FeatureCommentListViewController" bundle:nil];
cmtListController.title = Label.text;
cmtListController.isReviewed=isReviewed;
cmtListController.productDetail=productDetail;
cmtListController.dp_id=dp_id;
cmtListController.feature_name = #"&feature_good_id=2";
[self.navigationController pushViewController:cmtListController animated:YES];
}];
Should I declare the controller as a member of this viewController or just declare out of the block?
I solved this by alloc the FeatureCommentListViewController in the viewDidLoad function and use it in block.
1st. Im wondering why do you push a view controller in a block but not in the main thread? Isn't it important to give a quick response to the touch action?
2nd.[self.navigationController pushViewController:cmtListController animated:YES]; is in your block. Whenever you left the current navigationController what will the self.navigationController represent?
3rd. If you declare the viewController out of the block you can add __block in front of it as mentioned by Hermann Klecker.

Resources