Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some function not work #10

Closed
erickyim opened this issue May 26, 2015 · 9 comments
Closed

some function not work #10

erickyim opened this issue May 26, 2015 · 9 comments

Comments

@erickyim
Copy link

Hi, I think this engine is great! Thanks for your works!

I add a function tableView_didSelectRowAtIndexPath after tableView_heightForRowAtIndexPath in demo.js, like this:

    tableView_heightForRowAtIndexPath: function(tableView, indexPath) {
        return 60
    },
    tableView_didSelectRowAtIndexPath: function(tableView, indexPath) {
        console.log("did select row at index path");
    }

when I click cells of the table view, Xcode didn't log "did select row at index path".

@bang590
Copy link
Owner

bang590 commented May 26, 2015

@cyvoit By now, JSPatch can't add method to an OC class if the method not exists in OC, I'm figuring out a way to solve this problem, would be update soon.

@erickyim
Copy link
Author

I think tableView_didSelectRowAtIndexPath is an existing method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPathof protocol UITableViewDelegate.

@bang590
Copy link
Owner

bang590 commented May 26, 2015

@cyvoit it's a protocol, not an exists method.
[[[UITableViewController alloc] init] respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)] == NO

@wy19901227
Copy link

but why the other method of protocol can be run?

@bang590
Copy link
Owner

bang590 commented May 26, 2015

@wy19901227 because the base class UITableViewController implemented some of the methods.

@erickyim
Copy link
Author

    XCTAssertFalse([[[UITableViewController alloc] init] respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]);
    XCTAssertTrue([[[UITableViewController alloc] init] respondsToSelector:@selector(tableView:cellForRowAtIndexPath:)]);

Test succeeded!
Maybe because cellForRowAtIndexPath is a required method while didSelectRowAtIndexPath is an optional method.

@wy19901227
Copy link

how to test?

@erickyim
Copy link
Author

@wy19901227 add the test code to a test file, e.g. JSPatchTests.m and run the test target. Maybe it's another topic.

@bang590
Copy link
Owner

bang590 commented May 27, 2015

@cyvoit Solved in 653074f. We can add new method to OC class now.
The tableView_didSelectRowAtIndexPath is work now, but there is something wrong if the protocol method params type is not all id, will support protocol in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants