Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird (to me) issue with cocoa table views
    primarykey
    data
    text
    <p>I'm building a small app to learn Objective-C. I've tried reading some books books figured just 'jumping in' would be the best we to learn.</p> <p>Right now I'm a bit stuck though, I've looked at some of Apple's examples (and I believe I'm following them more or less). Anyway, my problem is this:</p> <p>When I create a window with a table in it, give the window some data and then open the window I have the data present and no tableView (probably because the NIB isn't loaded before I open the window?). When I open the window, my numberOfRowsInTableView function seems unable to find my data.</p> <p>I've included my full code for the .h and .m file and hope you can see what's wrong.. (probably something really silly)</p> <pre><code>// // MainWindow.h // Practice App // // #import &lt;Cocoa/Cocoa.h&gt; #import "mvmUser.h" @interface FriendStreamController : NSWindowController&lt;NSTableViewDelegate, NSTableViewDataSource&gt; @property (assign) IBOutlet NSTableView *myTableView; @property (nonatomic, retain) mvmUser *user; @property (nonatomic, retain) NSArray *activityData; -(void)setUserObject:(mvmUser *)user; -(void)createFriendstream; @end </code></pre> <p>and</p> <pre><code>// // MainWindow.m // Practice App // // #import "FriendStreamController.h" @interface FriendStreamController () @end @implementation FriendStreamController @synthesize myTableView = _myTableView; @synthesize user = _user; @synthesize activityData = _activityData; -(NSString *)windowNibName { return @"FriendStreamController"; } - (id)initWithWindow:(NSWindow *)window { return self; NSWindow *selfWindow = self.window; [selfWindow makeKeyAndOrderFront:self]; } - (void)windowDidLoad { [super windowDidLoad]; // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. } -(void)createFriendstream{ [self.myTableView reloadData]; } -(void) setUserObject:(mvmUser *)user { self.user = user; _activityData = [[NSArray alloc]initWithArray:self.user.apiResponse copyItems:YES]; NSLog(@"data 1st: %@, %@", _activityData, _myTableView); } -(NSInteger) numberOfRowsInTableView:(NSTableView *)tableView { NSLog(@"data 2nd: %@, %@", _activityData, _myTableView); int numRows = [_activityData count]; return [_activityData count]; } - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { NSLog(@"table view stuff"); // group the model (activityData) NSDictionary *dictionary = [_activityData objectAtIndex:row]; NSString *identifier = [tableColumn identifier]; if([identifier isEqualToString:@"ActivityCell"]) { NSTableCellView *cellView = [tableView makeViewWithIdentifier:identifier owner:self]; cellView.textField = [dictionary objectForKey:@"username"]; return cellView; } return nil; } @end </code></pre> <p>and my NSLOGs give me :</p> <pre><code>2012-07-13 00:07:14.550 Practice App[13571:f03] data 1st: ( { "activity_id" = 3122267; "activity_name" = "add_media"; avatar = "http://a1.media.mobyhub.com/avatar/41d3b6664cb8d8a55148364f4833c89e_60px.jpg"; "created_on" = "2012-07-12 23:37:50"; id = 3122267; moby = { "content_type" = photo; description = ""; id = 13271224; media = "http://a1.img.mobypicture.com/69f025622e87b1265d55395d877f1d83_view.jpg"; "short_url" = "http://moby.to/f8asii"; thumbnail = "http://a1.img.mobypicture.com/69f025622e87b1265d55395d877f1d83_square.jpg"; title = "@robertpaul @Paulpridephoto @mattebox @eastbayjay Set this to on. Preset URL saved in image EXIF data."; url = "http://www.mobypicture.com/user/simon_harper/view/13271224"; }; "name_first" = Simon; "name_last" = Harper; "user_id" = 454519; username = "simon_harper"; }, { "activity_id" = 3119852; "activity_name" = "add_media"; avatar = "http://a0.media.mobyhub.com/avatar/c2b0b2914f2738a7ded180fee123ad91_60px.jpg"; "created_on" = "2012-07-12 20:07:59"; id = 3119852; moby = { "content_type" = photo; description = ""; id = 13269679; media = "http://a0.img.mobypicture.com/d86fc26985b5cbf34b3a0aa3d3b40d5c_view.jpg"; "short_url" = "http://moby.to/tphlja"; thumbnail = "http://a0.img.mobypicture.com/d86fc26985b5cbf34b3a0aa3d3b40d5c_square.jpg"; title = "Iemand een idee hoe ik met dit bedrijf in contact kan komen? Formulier werkt niet, maar kan geen vragen stellen @nrc "; url = "http://www.mobypicture.com/user/Josk/view/13269679"; }; "name_first" = Jos; "name_last" = Kok; "user_id" = 2540; username = Josk; }, { "activity_id" = 3118440; "activity_name" = "add_media"; avatar = "http://a0.media.mobyhub.com/avatar/7e4bcc3f625b3d50ed49bd32eb65eafc_60px.jpg"; "created_on" = "2012-07-12 17:55:26"; id = 3118440; moby = { "content_type" = photo; description = ""; id = 13268834; media = "http://a3.img.mobypicture.com/ebfc0300aeb3bd54f1956cb22eea8cbb_view.jpg"; "short_url" = "http://moby.to/sg62tw"; thumbnail = "http://a3.img.mobypicture.com/ebfc0300aeb3bd54f1956cb22eea8cbb_square.jpg"; title = "Opel Ampera op de A9 vlakbij haarlem. Best mooie auto eigenlijk. Hoeveel rijd hij nu echt elektrisch op een volle accu?"; url = "http://www.mobypicture.com/user/vincente/view/13268834"; }; "name_first" = vincent; "name_last" = everts; "user_id" = 2487; username = vincente; }, { "activity_id" = 3118321; "activity_name" = "add_media"; avatar = "http://a0.media.mobyhub.com/avatar/402bff232d440ecf6a4a037830eb2780_60px.jpg"; "created_on" = "2012-07-12 17:39:40"; id = 3118321; moby = { "content_type" = photo; description = ""; id = 13268749; latlong = "52.067,4.32418"; media = "http://a2.img.mobypicture.com/d27abd1ac8b18f406f45f8621ef0e2d7_view.jpg"; "short_url" = "http://moby.to/3j1wie"; thumbnail = "http://a2.img.mobypicture.com/d27abd1ac8b18f406f45f8621ef0e2d7_square.jpg"; title = "Trots op @ChelseyWinkel die nu al haar P haalt :)"; url = "http://www.mobypicture.com/user/Mikevanrossum/view/13268749"; }; "name_first" = Mike; "name_last" = "van Rossum"; "user_id" = 28504056; username = Mikevanrossum; }, { "activity_id" = 3117532; "activity_name" = "add_friend"; avatar = "http://a1.media.mobyhub.com/avatar/f1459fef5a78c525ef60c47a706709bd_60px.jpg"; "created_on" = "2012-07-12 16:33:49"; id = 3117532; "name_first" = Berry; "name_last" = Helsloot; target = { avatar = "http://a0.media.mobyhub.com/avatar/e0f6b16e645594c96a6d8693969c787d_60px.jpg"; "name_first" = Mick; "name_last" = Harren; "user_id" = 427052; username = mickharren; }; "user_id" = 213700; username = bhelsloot; }, { "activity_id" = 3116839; "activity_name" = "add_media"; avatar = "http://a0.media.mobyhub.com/avatar/601a85e2a0279875ea558835fda56aef_60px.jpg"; "created_on" = "2012-07-12 15:23:29"; id = 3116839; moby = { "content_type" = photo; description = ""; id = 13268001; media = "http://a3.img.mobypicture.com/7bf755f874955c24bfa06e247d0d11ea_view.jpg"; "short_url" = "http://moby.to/yqg56x"; thumbnail = "http://a3.img.mobypicture.com/7bf755f874955c24bfa06e247d0d11ea_square.jpg"; title = "\U266c'Ice Ice Baby' - Vanilla Ice\U266a #nowplaying on #spotify http://open.spotify.com/track/3XVozq1aeqsJwpXrEZrDJ9"; url = "http://www.mobypicture.com/user/Dryxe/view/13268001"; }; "name_first" = Daan; "name_last" = "van der Plas"; "user_id" = 28780688; username = Dryxe; } ), (null) 2012-07-13 00:07:14.655 Practice App[13571:f03] data 2nd: (null), &lt;NSTableView: 0x7f887b364930&gt; </code></pre> <p>Hope you can give some help, would be awesome.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload