Note that there are some explanatory texts on larger screens.

plurals
  1. POReloaddata not call cellForRowatIndexPath
    primarykey
    data
    text
    <p>I create a UITableViewController using <strong>storyboard</strong>, and want to reload the tableview every time it detect a device(for bonjour protocol). However, the reload data method only calls numberofRows, but not call CellForRowatIndexPath. So I have nothing changed. The mutablearray I checked is always going correctly. NewObjects are added. But the tableview doesn't change with the array. So I am wondering if I set sth wrong here.</p> <p>From the NSLog I added, I found, I could load the tableview at the beginning with the initialized array</p> <pre><code> self.serviceArray = [[NSMutableArray alloc]initWithObjects:@"test", nil]; </code></pre> <p>But in the method </p> <pre><code> - (void)addService:(NSNetService *).... </code></pre> <p>Everytime I reload, the new object can be added to the mutableArray, but the tableview doesn't change with the array. (It called the numberOfRows, and I check the array size returned is not 0, but then it doesn't call the cellOfRowAtIndex)</p> <p>Here is my code</p> <p>.h file</p> <pre><code> #import &lt;UIKit/UIKit.h&gt; #import "Server.h" @interface BrowserViewController : UITableViewController &lt;ServerDelegate&gt; { Server *_server; NSMutableArray *_serviceArray; } @property (retain,nonatomic) NSMutableArray *serviceArray; @property (nonatomic,retain) Server *server; - (void)addService:(NSNetService *)service moreComing:(BOOL)more; @end </code></pre> <p>.m file</p> <pre><code> #import "BrowserViewController.h" @implementation BrowserViewController @synthesize serviceArray = _serviceArray; @synthesize server = _server; - (void) dealloc { [self.serviceArray release]; [self.tableView release]; [super dealloc]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; self.title = @"Service Browser"; _serviceArray = nil; self.serviceArray = nil; [self.tableView setDelegate: self]; [self.tableView setDataSource:self]; //actually I set this in the storyboard already [self.tableView reloadData]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; _serviceArray = nil; NSLog(@"viewwilldisappear"); } - (NSMutableArray *)serviceArray { if(nil == _serviceArray) { self.serviceArray = [[NSMutableArray alloc]initWithObjects:@"test", nil]; } else { NSLog(@"update array"); } return _serviceArray; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)addService:(NSNetService *)service moreComing:(BOOL)more{ [self.serviceArray addObject:service]; if (!more) { [self.tableView reloadData]; } } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return @"Connection Choices"; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.serviceArray count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *Cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (Cell == nil) { Cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease]; } NSString *text = [self.serviceArray objectAtIndex:indexPath.row]; Cell.textLabel.text = text; return Cell; } @end </code></pre> <p>I checked some solution, it's either delegate setting problem, or the array is null. or cell initialized without space. Is there any way to check what's the delegate of some method ?</p> <p>I also tried to create a tableview property in the .h file, linked IBOutlet, then synthesize it in the .m. But still doesn't work. Could anyone help me? </p> <p>Since a lot of tutorials are based on window-based application, could someone maybe provide me some tutorial using storyboard and using reloadData ? I could check if the Outlets are wrong.</p> <p>Thanks in advance.</p> <p><strong>UPDATE1</strong> AddService method is called in the appDelegate</p> <p>appDelegate.h </p> <pre><code> #import &lt;UIKit/UIKit.h&gt; #import "Server.h" @class BrowserViewController; @interface iphoneNetworkAppDelegate : NSObject &lt;UIApplicationDelegate,UITableViewDataSource, UITableViewDelegate, ServerDelegate&gt; { Server *_server; UIWindow *window; IBOutlet BrowserViewController *BrowserVC; } @property (strong, nonatomic) UIWindow *window; @end </code></pre> <p>appDelegate.m</p> <pre><code>#import "iphoneNetworkAppDelegate.h" #import "BrowserViewController.h" @implementation iphoneNetworkAppDelegate @synthesize window; - (void)dealloc { [window release]; [_server release]; _server = nil; [BrowserVC release]; BrowserVC = nil; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSString *type = @"TestingProtocol"; _server = [[Server alloc] initWithProtocol:type]; _server.delegate = self; NSError *error = nil; if(![_server start:&amp;error]) { NSLog(@"error = %@", error); } BrowserVC = [BrowserViewController alloc]; if (BrowserVC == nil) { NSLog(@"need to init"); } BrowserVC.server = _server; return YES; } #pragma mark Server Delegate Methods - (void)serverRemoteConnectionComplete:(Server *)server { NSLog(@"Server Started"); BrowserVC.server = server; } - (void)serverStopped:(Server *)server { NSLog(@"Server stopped"); } - (void)server:(Server *)server didNotStart:(NSDictionary *)errorDict { NSLog(@"Server did not start %@", errorDict); } - (void)server:(Server *)server didAcceptData:(NSData *)data { NSLog(@"Server did accept data %@", data); } - (void)server:(Server *)server lostConnection:(NSDictionary *)errorDict { NSLog(@"Server lost connection %@", errorDict); } - (void)serviceAdded:(NSNetService *)service moreComing:(BOOL)more { NSLog(@"service added in delegate"); [BrowserVC addService:service moreComing:more]; } #pragma mark - - (void)applicationWillTerminate:(UIApplication *)application { [_server stop]; [_server stopBrowser]; } </code></pre> <p>If the appDelegate setting is like this, reloadData cannot be called ?</p>
    singulars
    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