initWithNib and transfer data across views?

8 views
Skip to first unread message

Byron

unread,
Nov 18, 2009, 5:39:50 AM11/18/09
to iPhone Application Development Auditors
Hello, i am wondering if there is a way to use initWithNib and still
transfer data across views?
For example:

StatusTableView *statusView = [[StatusTableView alloc] initWithModel:
[people objectAtIndex:indexPath.row]];

with the above i can transfer my Person Object with all the data for
that particular cell to the next view controller, how can i create a
TableView instance with initWithNib and still transfer data?

Also.. can anyone please confirm for me if the following code is the
right way to create instances of a model from an array of usernames?
as this works but i feel it may not be the best way to go about it.

for (NSString *user in twitterUsers) {
NSDictionary *twitterInfo = [TwitterHelper
fetchInfoForUsername:user];
NSArray *statusInfo = [TwitterHelper fetchTimelineForUsername:user];

Person *person = [[Person alloc] initWithName:[twitterInfo
objectForKey:@"name"] userName:user photoUrl:[NSURL URLWithString:
[twitterInfo objectForKey:@"profile_image_url"]] status:[statusInfo
valueForKey:@"text"]];

[people addObject:person];

[person release]; }

Thanks
Byron

Byron

unread,
Nov 18, 2009, 5:52:38 AM11/18/09
to iPhone Application Development Auditors
Well i just worked it out.. i created a custom init method and put the
initWithNib as supers initialiser like so:

-(id)initWithData:(NSString*)data{
if (self = [super initWithNibName:@"DetailsTableView" bundle:nil]) {
self.title = data;
}
return self;

i'd still like to know if anyone can confirm the code in my first post
is correct?

Byron

Sukima

unread,
Nov 18, 2009, 6:08:06 AM11/18/09
to iPhone Application Development Auditors
First question. You could create a custom init method or a setter.
Here is an example: http://gist.github.com/237747

Second question. Looks good to me. That's exactly how I might do it.
Your idea of getting the data and storing it in a custom _model_ is
correct IMHO. How a model is used is a person preference. There are
many ways.

Byron

unread,
Nov 18, 2009, 7:19:13 AM11/18/09
to iPhone Application Development Auditors
Thanks for the example, i think i shall try the initWithPerson:
andNibName:
Reply all
Reply to author
Forward
0 new messages