I have a small issue in Updating the details in the view. How to reload a view after successful updation to change the details.
Below is my code. Please help me to find out the solution. Thanks in Advance.
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)viewWillAppear:(BOOL)animated
{
[self viewDidLoad];
[super viewWillAppear:animated];
[self.view setNeedsDisplay];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
profilearray=[[NSMutableArray alloc]initWithObjects:#"First Name:",#"Last Name:",#"Date of Birth:",#"Email:",#"Gender:",#"Address:",#"Country:",#"State:",#"City:",#"ZipCode:",#"Phone:",#"Guardian / Caretaker Details:",#"Name:",#"Relationship:",#"Email:",#"Doctor Details:",#"Name:",#"Phone:",#"Email:",#"Insurance Details:",#"Name:",#"Email:",nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [profilearray count];
}
- (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];
}
cell.textLabel.text = [profilearray objectAtIndex:indexPath.row];
if(indexPath.row==0)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:#"FirstName"];
}
if(indexPath.row==1)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:#"LastName"];
}
if(indexPath.row==2)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:#"DOB"];
}
if(indexPath.row==3)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:#"Email"];
}
if(indexPath.row==4)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:#"Gender"];
}
if(indexPath.row==5)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:#"Address"];
}
return cell;
}
use [tableView reloadData] for updating tableview
Simple Use this Do not need to view refresh or reload
-(void)viewWillAppear:(BOOL)animated
{
[tableView reloadData]
[super viewWillAppear:animated];
}
Your data source array profilearray keeps getting re-assigned the same value every time the view appears. Maybe initialise it once in viewDidLoad.
After the array is updated, use [tableView reloadData] to reload the table view.
Do not call viewDidLoad on your own, and get rid of setNeedsDisplay for now.
Just use this.
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
profilearray=[[NSMutableArray alloc]initWithObjects:#"First Name:",#"Last Name:",#"Date of Birth:",#"Email:",#"Gender:",#"Address:",#"Country:",#"State:",#"City:",#"ZipCode:",#"Phone:",#"Guardian / Caretaker Details:",#"Name:",#"Relationship:",#"Email:",#"Doctor Details:",#"Name:",#"Phone:",#"Email:",#"Insurance Details:",#"Name:",#"Email:",nil];
[tableView reloadData];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
profilearray:- Perhaps this is your array from where you are getting data in tableview and also storing data in it
viewWillAppear :- this method is called when view is appear
[tableView_Outlet reloadData] :- this method reload your tableview with new data
So in this scenario never call viewWillAper Because this is not standard way to do
Find point where your data is updated then call "reloadData"
For more about viewWillApear hit
Thanks
Related
I need to delete a row in my tableview to update my changes.
I have a delete button in each cell (tableViewCellController) - look at the picture.
Screenshot
After I click the delete button, the UI button method calls the delegated method in tableViewController. The delete method update the data source (my model) and i want to update also the screen (now the method reload all the data, but I want to update the new change - delete row from screen).
I tried to do this with the following function but i don't have a sender (as i said the button is pressed in the cell, but I actually make the change on the tableView)
Function:
- (IBAction)contactDelete:(id)sender{
[[[ModelUser instance] getUser:self.actualLoggedUser] removeFavUser:self.contactUserId];
NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)sender.superview];
[self.tableView deleteRowsAtIndexPaths:
[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
favoritesTableViewCell:
#import "favoritesTableViewCell.h"
#import "ModelUser.h"
#implementation favoritesTableViewCell
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (IBAction)favoritesDeleteFromFav:(id)sender {
[[[ModelUser instance] getUser:self.actualLoggedUser] removeFavUser:self.contactUserId];
[self.delegate onFavDeleteClick];
}
favoritesTableViewController:
- (void)viewDidLoad {
[super viewDidLoad];
self.actualLoggedUser = [NSString stringWithFormat:#"2"];
[self reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)reloadData {
NSLog(#"Favorites tab was loaded");
//get id of my favorite contacts
myFavListId = [[ModelUser instance] getUser:self.actualLoggedUser].contactsFavoriteList;
//get data of my favorites contacts
myFavListContactsData = [[NSMutableArray alloc] init];
for (int i=0; i < [myFavListId count] ; i++) {
User* us = [[ModelUser instance] getUser:([myFavListId objectAtIndex:i])];
[myFavListContactsData addObject:us];
}
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (void) viewDidAppear:(BOOL)animated {
[self reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return myFavListContactsData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
favoritesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"favoriteCell" forIndexPath:indexPath];
User *us = [myFavListContactsData objectAtIndex:indexPath.row];
//setting cell data
cell.actualLoggedUser = self.actualLoggedUser;
cell.contactUserId = us.userId;
cell.contactName.text = [NSString stringWithFormat:#"%# %#",us.fname,us.lname];
[cell.contactImage setImage: [UIImage imageNamed:us.imageName]];
cell.delegate = self;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
User *us = [myFavListContactsData objectAtIndex:indexPath.row];
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
userDetailsProfile* udVC = [sb
instantiateViewControllerWithIdentifier:#"userDetailsProfile"];
udVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
udVC.userDetailId = [NSString stringWithFormat:#"%#", us.userId];
[self showViewController:udVC sender:self];
}
- (void)onFavDeleteClick {
[self reloadData];
}
#end
You need to update datasource and delete the cell in your delegate callback that is invoked from your cell class (onFavDeleteClick delegate method of favoritesTableViewCell class, in your case).
The process should be something like this:
In your "favoritesTableViewCell.h", declare a protocol containing onFavDeleteClick method. I think you have already done with this step. What you need to do is to update the method signature as -(void) onFavDeleteClick:(favoritesTableViewCell*)cell.
From "favoritesTableViewCell.m" call favoritesDeleteFromFav method like this:
-(IBAction)favoritesDeleteFromFav:(id)sender {
[self.delegate onFavDeleteClick:self];
}
Now in your view controller where the main UITableView exists implement the callback method like this:
-(void)onFavDeleteClick:(favoritesTableViewCell*)cell {
//update model
[[[ModelUser instance] getUser:self.actualLoggedUser] removeFavUser:self.contactUserId];
//update table view
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
if (indexPath) {
[self.tableView deleteRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
And this is everything you need to do to get your desired effect.
I have a menu with two items, Login and Settings, displayed in a tableView. Login and Settings are stored in an NSArray. On ViewDidLoad I am checking if user exist in NSUserDefaults. If user exist then change the Login to Logout and vice versa. The issue is that on ViewDidLoad it only changes the name once when the application is opened after being cleared from cache. Therefore, in order to see the change after login in or login out you need to clear the application from cache and re-open it. I want the changes to apply immediately. Every time the menu button click before the menu open and viewDidAppear is accessed. I know this because I placed a break point and traced it. It does what is supposed to. But the it never changes the value of login to logout or vice versa.
MenuController.
-(void)ChangeLoginLabel {
NSUserDefaults *data = [NSUserDefaults standardUserDefaults];
NSString *User = [data objectForKey:#"User"];
if(User==nil) {
_extraMenuItems = [[NSMutableArray alloc] initWithObjects:#"Settings", #"Login", nil];
}
else {
_extraMenuItems = [[NSMutableArray alloc] initWithObjects:#"Settings", #"Logout", nil];
}
}
- (void)viewWillAppear:(BOOL)animated {
[self ChangeLoginLabel];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self ChangeLoginLabel];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
return self.extraMenuItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = #"Formal";
UITableViewCell *cell = [self.extraTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSString *cellValue = [self.extraMenuItems objectAtIndex:indexPath.row];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.numberOfLines = 0;
cell.textLabel.text = cellValue;
cell.textLabel.textColor = [UIColor blackColor];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
NSLog(#"Settings cell tapped!");
}
else if (indexPath.row == 1)
{
//closes when login view appears
[self.slidingViewController resetTopView];
NSString *LoginTextLabel = [self.extraMenuItems objectAtIndex:indexPath.row];
if([LoginTextLabel isEqualToString:#"Logout"]) {
}
else {
UIViewController * vc = [self.storyboard instantiateViewControllerWithIdentifier:#"Login"];
[self presentViewController:vc animated:YES completion:nil];
}
}
// Deselect the row
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Logs
2014-12-12 13:06:53.290 xxx[1695:270056] _extraMenuItems: (
Settings,
Login
)
2014-12-12 13:07:04.290 xxx[1695:270056] _extraMenuItems: (
Settings,
Logout
)
How can I force the array to change the value immediately when the user logged in or logged out?
If I'm understanding correctly, you're trying to update the label in your table based on the change in NSUserDefaults as triggered by a login/logout from another view controller; so when you return to the MenuViewController, ChangeLoginLabel is triggered by the viewDidAppear, the extraMenuItems array is in fact set to contain the appropriate values, and you expect the labels in the table to change accordingly. But the problem is, that you're not reloading the table upon your return to the view.
So first off, I'd recommend removing [self ChangeLoginLabel]; from your viewDidLoad since it's redundant. And secondly, I'd recommend changing your ChangeLoginLabel method to include a table reload, like so:
-(void)ChangeLoginLabel {
NSUserDefaults *data = [NSUserDefaults standardUserDefaults];
NSString *User = [data objectForKey:#"User"];
if(User==nil) {
self.extraMenuItems = [[NSMutableArray alloc] initWithObjects:#"Settings", #"Login", nil];
}
else {
self.extraMenuItems = [[NSMutableArray alloc] initWithObjects:#"Settings", #"Logout", nil];
}
[self.tableView reloadData];
}
- (void)viewWillAppear:(BOOL)animated {
[self ChangeLoginLabel];
}
Or if you'd prefer just to reload the relevant row you can replace [self.tableView reloadData]; with:
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
Do you want viewWillAppear instead? viewDidAppear happens after the view already is rendered I believe.
call
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self ChangeLoginLabel];
}
or
- (void)viewDidAppear:(BOOL)animated {
[super viewDifAppear:animated];
[self ChangeLoginLabel];
}
I'm currently making an application that can edit the information stored in certain table view cells by clicking on them and then going to a separate view controller.
Once the changes are made, a save button is pressed, and the fields are updated on parse.com
My issue is that once I go back to my main tableViewController, the table cells aren't updating unless I completely restart the application, at which point everything shows as updated.
I've called the [self.tableView reloadData] method like in the iOS tutorials, but it just won't seem to update.
Here's the .m file for the controller that I'm trying to update.
#interface ProspectsTableViewController ()
#end
#implementation ProspectsTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.currentUser = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:#"Prospect"];
[query orderByAscending:#"prospectName"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(#"Error in prospect cells");
}
else {
self.allProspects = objects;
NSLog(#"%#", self.allProspects);
[self.tableView reloadData];
}
}];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.allProspects count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ProspectCell";
UITableViewCell *prospectCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
PFObject *prospect = [self.allProspects objectAtIndex:indexPath.row];
prospectCell.textLabel.text = prospect[#"prospectName"];
return prospectCell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"cell pressed");
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[self performSegueWithIdentifier:#"showProspectInfo" sender:cell];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"showProspectInfo"]) {
ProspectInfoViewController *transferViewController = segue.destinationViewController; //prepares an instance of the prospectsTableViewController so we can pass our information over to the next view controller
PFObject *prospect = self.allProspects[self.tableView.indexPathForSelectedRow.row]; //selects the information from the prospect at the cell tapped on
transferViewController.name = prospect[#"prospectName"];
transferViewController.phone = prospect[#"phoneNumber"];
transferViewController.email = prospect[#"email"];
transferViewController.objectId = [prospect objectId];
}
}
#end
any ideas? I've been trying to figure this one out for quite some time now
Thanks in advance!
It doesn't look like you're calling [self.tableView reloadData]; after coming back to the table view controller. Try adding this to your table view controller's implementation to refresh your table view whenever your view controller is about to appear:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView reloadData];
}
try reloadData in viewDidAppear
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableView reloadData]
}
I'm making an application with a tableview list of contacts that can be reached via a tab-controller at the bottom.
I copied (literally copy/pasted) from the example Master Detail Application and tried to make sure all storyboard references lined up.
#import "ContactsTableViewController.h"
#import "ContactViewController.h"
#interface ContactsTableViewController () {
NSMutableArray *_objects;
}
#end
#implementation ContactsTableViewController
- (void)awakeFromNib
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.clearsSelectionOnViewWillAppear = NO;
self.preferredContentSize = CGSizeMake(320.0, 600.0);
}
[super awakeFromNib];
// [self.tableView setDelegate:self]; // From (unsuccesfully) trying https://stackoverflow.com/questions/16311393/how-to-insert-items-to-a-uitableview-when-a-uibutton-is-clicked-in-ios
// [self.tableView setDataSource:self];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.contactViewController = (ContactViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; // Crashes here
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _objects.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath]; // Crashes here
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
NSDate *object = _objects[indexPath.row];
self.contactViewController.detailItem = object;
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}
#end
It crashes on the first line in CellRowAtIndexPath. Since I was having trouble I also took the advice in How to insert items to a UITableView when a UIButton is clicked in iOS but it didn't solve my problem.
This is just incredibly frustrating, because as far as I can tell my code is (except for names) exactly the same as the example application.
edit: Exception message is
'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
Alex - When using storyboards and the new prototype cell feature in xCode, you have to set an identifier value in Interface Builder whose value should match what is in your code.
So notice you have this line:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
In this case, your cell identifier is "Cell"
Can you confirm that in Interface Builder/Storyboard, your table view cell's identifier is set to the same?
As an example, here's a screenshot from a sample app I was building (Notice my Indentifier field on the right):
I would recommend this
-(void)ViewDidLoad{
[tableView registerClass:[MyCell class] forCellReuseIdentifier:#"Cell"];
}
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
[tableView reloadData]; //this will trigger cellForRowAtIndexPath again with the updated array
}
and would you please post your error.
You should not use [self.tableView insertRowsAtIndexPaths: withRowAnimation:];. Instead of this you should call [talbeView reloadData] method.
I'm trying to use recursive table view but when I click to any cell and second UITableView appears (created by tableView:didSelectRowAtIndexPath:), there are just empty rows without any text.
Can somebody help please ?
#implementation RSTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
[self.tableView registerClass:[RSCell class] forCellReuseIdentifier:#"bbaCell"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.array = [NSMutableArray arrayWithObjects:#"1",#"2",#"3", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RSTableViewController *rsTableView = [[RSTableViewController alloc] initWithStyle:UITableViewStylePlain];
rsTableView.tableView.delegate = self;
[self.navigationController pushViewController:rsTableView animated:TRUE];
[tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"bbaCell";
RSCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.label1.text = [self.array objectAtIndex:indexPath.row];
cell.label2.text = [self.array objectAtIndex:indexPath.row];
return cell;
}
#end
A. [self.navigationController pushViewController:rsTableView animated:TRUE] is wrong, there's no such thing as TRUE, there's only YES.
B. I feel like you're doing something very wrong but anyway, you method should be the following:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RSTableViewController *rsTableView = [[RSTableViewController alloc] initWithStyle:UITableViewStylePlain];
// each rs table view instance is it's own delegate and datasource
rsTableView.tableView.delegate = rsTableView;
// you forgot to add this line:
rsTableView.tableView.dataSource = rsTableView;
[self.navigationController pushViewController:rsTableView animated:YES];
// what's this line for ?? the new ViewController will automatically call all the necessary methods. please remove it.
[tableView reloadData];
}
please check the syntax, and secondly, what's RSTableViewController base ViewController ?? is it UITableViewController ??
make sure you're setting the delegate and datasource properly.