Note that there are some explanatory texts on larger screens.

plurals
  1. PONSMutableArray not updating and UITableView not reloading
    primarykey
    data
    text
    <p>I'm creating a chat application. I have 2 methods in my view controller one for sending and one for receiving the messages. In the sending method i create a NSMutableDictionary with two objects ..</p> <pre><code>NSMutableDictionary *msgFilter = [[NSMutableDictionary alloc] init]; [msgFilter setObject:messageStr forKey:@"msg"]; [msgFilter setObject:@"you" forKey:@"sender"]; [messages addObject:msgFilter]; </code></pre> <p>"messages" is my main NSMutableArray for holding all the messages, whose property is set and synthesized and allocated. When i send the message it is properly added into the NSMutableArray and the UITableView is updated showing me the values in the cell. </p> <p>I have a method in my appDelegate to check for messages received and use the same procedure to parse the data and store it in an NSMutableDictionary. This dictionary is then passed to the viewcontroller and added into the same NSMutableArray(messages) and i then call [self.chattable reloadData]. But this doesn't do anything. When i nsloged the NSMutableArray it only had the received message not the whole data(send + received).</p> <h2>Why is it not adding the received messages into the same array and why is it not refreshing my table. I've been trying to get it to work for days now...Plz help..</h2> <p>//Recives message section</p> <pre><code>NSMutableDictionary *msgFilter = [myDelegate msgFilter]; [messages addObject:msgFilter]; [self.tView reloadData]; </code></pre> <p>//Tableview section</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [messages count]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } NSDictionary *s = (NSDictionary *) [messages objectAtIndex:indexPath.row]; NSString *sender = [s objectForKey:@"sender"]; NSString *message = [s objectForKey:@"msg"]; if ([sender isEqualToString:@"you"]) { cell.detailTextLabel.text = [NSString stringWithFormat:@"TX: %at", message]; } else { cell.detailTextLabel.text = [NSString stringWithFormat:@"RX: %at", message]; } return cell; } </code></pre>
    singulars
    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.
 

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