Side menu item is totally blank after click - ios

After opening the side menu, whenever I click any item of it the side menu goes totally blank and displays only a white screen.
How can I solve this issue?
viewCotroller file:
enum TranslateDirection {
LEFT, RIGHT
};
const float TRANSLATE_CONST = 250;
float translateX = TRANSLATE_CONST;
enum TranslateDirection td = RIGHT;
bool flag = 0;
- (void)viewDidLoad {
[super viewDidLoad];
NavViewController *view;
view = [self.storyboard instantiateViewControllerWithIdentifier:#"navigationView"];
[self.navigationController.view.window insertSubview:view.view atIndex:0];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)showMenu:(id)sender {
[UIView animateWithDuration:0.5f
delay:0.02
options:UIViewAnimationOptionCurveEaseIn
animations:^{
if (td == LEFT) {
translateX = 0;
} else if (td == RIGHT) {
translateX = TRANSLATE_CONST;
}
CGAffineTransform trans = CGAffineTransformMakeTranslation(translateX, 0);
self.navigationController.view.transform = trans;
}
completion:^(BOOL finished){
if (td == LEFT) {
td = RIGHT;
} else if (td == RIGHT) {
td = LEFT;
}
}
];
/*if (flag == 0) {
[_showMenubar setStyle:UIBarButtonSystemItemAdd];
flag = 1;
} else {
flag = 0;
}*/
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)menu:(id)sender {
}
#end
sideMenuFile Code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//_navItems = [[NSMutableArray alloc] initWithObjects:#"abc", #"abc", #"abc", nil];
_navItems = [NSArray arrayWithObjects:#"Inbox", #"* Important and unread", #"* Starred", #"* Everything", #"Sent Mail", #"Drafts", #"Spam" ,nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return #"Hello";
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
return #" bye";
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_navItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleIdentifier = #"SimpleIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleIdentifier];
}
// Configure the cell...
/*cell.textLabel.font = [UIFont fontWithName:#"Sans Serif" size:12];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.backgroundColor = [UIColor clearColor];*/
cell.textLabel.text = [_navItems objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

Related

UITableViewCell numberOfLines not work at first time

I have a UILabel in a UITableViewCell, I want it to be multilines according to context, and I use masonry to manage autolayout, here is the code
CommunityTableViewCell.m :
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
_postContentLabel = [UILabel new];
_postContentLabel.numberOfLines = 2;
_postContentLabel.font = DefaultFont(15);
_postContentLabel.textColor = COLOR(117, 117, 117);
[self.contentView addSubview:_postContentLabel];
[self makeConstraints];
}
return self;
}
- (void)makeConstraints{
[_postContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_userAvatar);
make.right.equalTo(_groupNameButton);
make.top.equalTo(_postTitleLabel.mas_bottom).offset(20);
make.height.greaterThanOrEqualTo(#20);
}];
}
- (void)updateCellWithModel:(PostsModel *)model{
if (model.content && ![model.content isEqualToString:#""]) {
_postContentLabel.text = model.content;
_postContentLabel.preferredMaxLayoutWidth = _postContentLabel.frame.size.width;
[_postContentLabel sizeToFit];
} else{
_postContentLabel = nil;
[_postContentLabel removeFromSuperview];
}
[self updateConstraints];
}
- (void)updateConstraints {
//some other code here
[super updateConstraints];
}
CommunityViewController.m :
- (void)viewDidLoad {
[super viewDidLoad];
_communityTableView = [UITableView new];
_communityTableView.delegate = self;
_communityTableView.dataSource = self;
_communityTableView.estimatedRowHeight = 80;
_communityTableView.rowHeight = UITableViewAutomaticDimension;
[_communityTableView registerClass:[CommunityTableViewCell class] forCellReuseIdentifier:#"CommunityTableViewCell"];
[self.view addSubview:_communityTableView];
[self makeConstraints];
[self requestPostData];
}
- (void)makeConstraints{
[_communityTableView mas_makeConstraints:^(MASConstraintMaker *make) {
UIEdgeInsets padding = UIEdgeInsetsMake(0, 0, 0, 0);
make.edges.equalTo(self.view).insets(padding);
}];
}
- (void)requestPostData{
[[NetEngine engine] GET:[NSString stringWithFormat:#"posts"] success:^(id responseObject) {
//receive the data
[self.communityTableView reloadData];
} failure:^(NSError *error) {
}];
}
#pragma mark - TableView DataSource & Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _postArrary.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CommunityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CommunityTableViewCell" forIndexPath:indexPath];
PostsModel *model = _postArrary[indexPath.row];
//some other code
[cell updateCellWithModel:model];
return cell;
}
enter code here
It doesn't show up to 2 lines as I wish, it shows only one line, but when I scroll down and back or pull to refresh the tableview, it shows 2 lines.
I don't know what's going on.

cellForRowAtIndexPath not called when compiled with xcode 6.1

In my app I have a popup with a [table view][1] .
When compiled with Xcode 5.1 everything works fine, but the same code compiled with Xcode 6.1 failed to call the [cellForRowAtIndexPath][3] [delegate][4] method.
The other delegate meths are called.
One intersting point is self.tableView.rowHeight; returns -1
I have tried explicitly setting the delegate and data source to self but that makes not difference
The class is called by the following code;
`-(IBAction)selectLanguage:(id)sender
{
ATLMLanguagePopoverTableViewController *pvc = [[ATLMLanguagePopoverTableViewController alloc] initWithNibName:nil bundle:nil];
pvc.target = self;
pvc.action = #selector(popoverDidSelectItem:);
pvc.items = [[[ATLMLibraryManager getManager]libraryDefaults]getAvailableLanguageNames];
_myPopoverController.contentViewController = pvc;
[_myPopoverController setPopoverContentSize:[pvc popoverContentSize]];
[_myPopoverController presentPopoverFromBarButtonItem:(UIBarButtonItem *)sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
`
Hear is the definition of the class
/
/ LanguagePopoverTableViewController.m
// SalesAid
//
// Created by phuang on 1/16/13.
// Copyright (c) 2013 Align Technology. All rights reserved.
//
#import "ATLMLanguagePopoverTableViewController.h"
#import "ATLMLocalizationManager.h"
#import "ATLMUtils.h"
#interface ATLMLanguagePopoverTableViewController ()
#end
#implementation ATLMLanguagePopoverTableViewController
#synthesize items, selectedItem, target, action;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
selectedItem = -1;
target = nil;
action = NULL;
}
return self;
}
-(void) resetLocalization {
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)setItems:(NSArray *)newItems {
items = [newItems copy];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
selectedItem=0;
NSString *curLang = (NSString *) [[ATLMLocalizationManager getManager]getCurrentLanguage] ;
for(int i = 0; i < items.count ; i++ ){
if([curLang isEqualToString:(NSString *)[items objectAtIndex:i]]){
selectedItem = i;
break;
}
}
NSIndexPath *i = [NSIndexPath indexPathForRow:selectedItem inSection:0];
[self.tableView selectRowAtIndexPath:i animated:NO scrollPosition:UITableViewScrollPositionNone];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (CGSize)popoverContentSize {
NSInteger rowHeight = self.tableView.rowHeight;
UITableView *tv = self.tableView;
rowHeight = 50;
return CGSizeMake(100, [items count] * rowHeight);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.font = [UIFont systemFontOfSize:14];
UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
myBackView.backgroundColor = [ATLMUtils getAlignBlue];
cell.selectedBackgroundView = myBackView;
[cell setSelectedBackgroundView: myBackView ];
NSString *textLabelKey = [items objectAtIndex:[indexPath indexAtPosition:1]];
cell.textLabel.text = ATLMLocalizedString(textLabelKey, nil);
cell.textLabel.textAlignment = NSTextAlignmentCenter;
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedItem = indexPath.row;
if (target != nil && action != NULL) {
[target performSelector:action withObject:self];
}
}
#end
`
OK to answer my own question;
Basically the code adds the model to the view controller after the init method is called. However is seem the thread model has changed a bit and the view is created before the model is added so the row count in the model is zero
The solution is to pass the model as part of the init method.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil items:(NSArray *)itemArray
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
items = [itemArray copy];
selectedItem = -1;
target = nil;
action = nil;
}
return self;
}

Putting iPhone to sleep hides tableview cells [duplicate]

This question already has answers here:
UITableView cells strangely disappearing
(2 answers)
Closed 9 years ago.
Very strange problem here.
Essentially what is happening is that our Tableview cells are becoming hidden in some cases when we simply put the app to sleep and then re-unlock. Our normal tableview looks like this:
And then when we re-open the app it will look like this:
All the rows and sections are set correctly, yet the cells are hidden.:
When this happens, our cellForRowAtIndexPath no longer gets called. This surely has to be the problem. Has anyone ever seen behavior like this? Here is how we set up the tableview. (sorry it is long)
//
// SPHomeViewController.m
// Spek
#interface SPHomeViewController () <UITableViewDataSource, UITableViewDelegate, MKMapViewDelegate, SPCreationViewDelegate, UIAlertViewDelegate, CLLocationManagerDelegate>
#property (nonatomic, strong) UITableView* tableView;
#property (nonatomic, strong) NSMutableArray* tableDatasource;
#property (nonatomic, strong) NSMutableArray* datasource;
#property (nonatomic, strong) NSMutableArray* friendsDatasource;
#property (nonatomic, strong) UISegmentedControl* userFilterSegment;
#property (nonatomic) BOOL isLoadingData;
#end
#implementation SPHomeViewController
#synthesize datasource = _datasource;
#synthesize friendsDatasource = _friendsDatasource;
#synthesize tableDatasource = _tableDatasource;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
//[[SPLocationManager locationManager] startUpdatingLocationForSig];
[self setNeedsStatusBarAppearanceUpdate];
self.view.backgroundColor = [UIColor colorWithRed:230.0f/255.0f green:230.0f/255.0f blue:230.0f/255.0f alpha:1.0];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - kTopBarHeight)];
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
if (self.creationView.center.y > self.view.frame.size.height) {
self.creationView = nil;
}
NSLog(#"Mem warning");
}
//****************************************
//****************************************
#pragma mark - UITableViewDelegate/DataSource
//****************************************
//****************************************
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"INDEX PATH ROW: %d AND SECTION: %d", indexPath.row, indexPath.section);
if (indexPath.section == 0) {
UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"SPMapCellSpace"];
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = [[UIView alloc] init];
cell.selectedBackgroundView = [[UIView alloc] init];
return cell;
} else if (indexPath.section == self.tableDatasource.count + 1) {
UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"SPBottomCellSpace"];
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = [[UIView alloc] init];
cell.selectedBackgroundView = [[UIView alloc] init];
return cell;
}
SPMark* mark = self.tableDatasource[indexPath.section - 1];
NSString* reuseId = [SPHomeViewController cellIdentifierFromData:mark];
SPTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
if (cell == nil) {
cell = [SPTableViewCell cellFromMark:mark reuseID:reuseId];
[cell updateView:YES];
}
[cell addDataToCell:mark];
if (indexPath.section >= self.tableDatasource.count - 2 && !self.isLoadingData && self.pageNumber != -1) {
self.fetchNextPage = YES; // When the scrollview stops it will load more data if available.
}
return cell;
}
- (unsigned int)getPageNumber {
return (self.userFilterSegment.selectedSegmentIndex == 0) ? self.pageNumber : self.friendsPageNumber;
}
- (void)setCurrentPageNumber:(unsigned int)page {
if (self.userFilterSegment.selectedSegmentIndex == 0) {
self.pageNumber = page;
} else {
self.friendsPageNumber = page;
}
}
- (void)incrementCurrentPageNumber {
if (self.userFilterSegment.selectedSegmentIndex == 0) {
self.pageNumber++;
} else {
self.friendsPageNumber++;
}
}
// Every cell has a section header so this should be equal to the number of speks returned from the server
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(#"section count is: %d",self.tableDatasource.count + 2 );
return self.tableDatasource.count + 2; // Add two because the mapview needs to go on the top and extra spacing at the bottom.
}
// There is a section for every cell, so there is only one cell per section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return kMapHeight+2;
} else if (indexPath.section == self.tableDatasource.count + 1) {
return kExtraSpaceBelowHomeView;
}
SPMark* mark = self.tableDatasource[indexPath.section - 1];
return [SPTableViewCell cellHeightForMark:mark];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 || indexPath.section == self.tableDatasource.count + 1) {
cell.backgroundColor = [UIColor clearColor];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 || indexPath.section == self.tableDatasource.count + 1)
return;
SPMark* mark = self.datasource[indexPath.section - 1 ];
SPMarkViewController* markVC = [SPMarkViewController withMark:mark];
[markVC displayData];
[self.navigationController pushViewController:markVC animated:YES];
}
-(void)reloadTableview {
[self.tableView setDelegate:self];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[self.tableView setNeedsDisplay];
});
}
- (void)showNoItems {
if (self.tableDatasource.count == 0 && self.accuracyBad == NO) {
self.opaqueIcon.hidden = NO;
self.noItems.hidden = NO;
self.beTheFirst.hidden = NO;
self.downArrow.hidden = NO;
self.noItemsBackround.hidden = NO;
[self.view bringSubviewToFront:self.noItemsBackround];
[self.view bringSubviewToFront:self.downArrow];
[self.view bringSubviewToFront:self.beTheFirst];
[self.view bringSubviewToFront:self.noItems];
[self.view bringSubviewToFront:self.opaqueIcon];
}
}
- (void)showTableView {
if (self.tableDatasource.count != 0) {
self.noItems.hidden = YES;
self.beTheFirst.hidden = YES;
self.downArrow.hidden = YES;
self.noItemsBackround.hidden = YES;
self.opaqueIcon.hidden = YES;
[self.view sendSubviewToBack:self.noItemsBackround];
[self.view sendSubviewToBack:self.downArrow];
[self.view sendSubviewToBack:self.beTheFirst];
[self.view sendSubviewToBack:self.noItems];
[self.view sendSubviewToBack:self.opaqueIcon];
}
}
//****************************************
//****************************************
#pragma mark - Setters/Getters
//****************************************
//****************************************
- (NSMutableArray*)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
if (!self.firstLoad) {
[self loadDataForPagination:NO];
}
}
return _datasource;
}
- (NSMutableArray*)friendsDatasource {
if (!_friendsDatasource) {
_friendsDatasource = [NSMutableArray array];
if (!self.firstLoad) {
[self loadDataForPagination:NO];
}
}
return _friendsDatasource;
}
- (NSMutableArray*)tableDatasource {
if (!_tableDatasource) {
_tableDatasource = (self.userFilterSegment.selectedSegmentIndex == 0) ? self.datasource : self.friendsDatasource;
}
return _tableDatasource;
}
- (SPCreationView*)creationView {
if (!_creationView) {
UIView* window = [SPUtils getAppDelegate].window;
CGSize viewSize = window.frame.size;
CGRect startFrame = CGRectMake(0, viewSize.height, [SPUtils screenWidth], [SPUtils screenHeight]);
_creationView = [SPCreationView creationView:startFrame delegate:self];
[window insertSubview:_creationView belowSubview:self.creationButton];
_creationView.frame = startFrame;
}
return _creationView;
}
- (void)setTableDatasource:(NSMutableArray *)tableDatasource {
_tableDatasource = tableDatasource;
[self preFetchImages];
dispatch_async(dispatch_get_main_queue(), ^{
if(_tableDatasource == nil || _tableDatasource.count == 0) {
[self showNoItems];
} else {
[self showTableView];
}
[self reloadTableview];
});
}
- (void)setDatasource:(NSMutableArray *)datasource {
_datasource = datasource;
}
- (void)setFriendsDatasource:(NSMutableArray *)friendsDatasource {
_friendsDatasource = friendsDatasource;
}
#end
If you think it's a AppDelegate problem, we don't do anything with this controller in there, so I don't see how it could be.
I've only seen this occur previously when I was reloading data (incorrectly) from a background thread. I see you're trying to push the reloads onto the main thread already.
It looks like you're flailing a bit trying to be sure updates are occurring on the main thread. You should probably just verify that your actions are occurring on main by checking [NSThread isMainThread] rather than making your code async to the main thread, making lots of async flow changes can lead to unexpected behavior.
That said, since this only happens on wake from sleep maybe you have some background mode on and you aren't updating the UI from the correct thread there?

IndexPath.row on a button?

I have an app in which you can have some details of something and then inside that thing you have a sub-category of things. I have made a button as there was not enough room for a navigation item and I can't seem to be able to call only the items that are assigned to that in my nsmutablearray. I have tried to used initWithIndexPath:indexPath.row though it comes up with this error:
Use of undeclared identifyer "indexPath"; did you mean "NSIndexPath"
This is the code for my tableView inside my tableView:
#import "PRViewController.h"
#import "Patient.h"
#import "LSAppDelegate.h"
#import "LSViewController.h"
#import "LSAppDelegate.h"
#import "Patient.h"
#import "PatientController.h"
#import "AddPatientController.h"
#import "treatmentController.h"
#interface PRViewController ()
#end
#implementation PRViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.title = #"Treatments";
LSAppDelegate *delegate = (LSAppDelegate *)[[UIApplication sharedApplication] delegate];
patients = delegate.patients;
[[UIToolbar appearance] setTintColor:[UIColor brownColor]];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)add:(id) sender{
[self.tableView reloadData];
[self.tableView setEditing:YES animated:YES];
if(self.tableView) {
NSMutableArray *indices = [[NSMutableArray alloc] init];
for (int i=0; i < patients.count; i++) {
[indices addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
NSArray *lastIndex = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:patients.count inSection:0]];
if (self.tableView) {
for (int i=0; i < patients.count; i++) {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[indices objectAtIndex:i]];
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
}
}
}
[self.tableView setEditing:NO animated:YES];
treatmentController *AddPatient = [[treatmentController alloc] init];
[self.navigationController pushViewController:AddPatient animated:YES];
[super setEditing:NO animated:NO];
}
-(void)setEditing:(BOOL)editing animated:(BOOL) animated {
if ( editing != self.editing ) {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
}
}
#pragma mark UITableViewDataSource Methods
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:#"cell"];
if ( nil == cell ) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
NSLog(#"indexPath.row = %d, patients.count = %d", indexPath.row, patients.count);
Patient *thisPatient = [patients objectAtIndex:indexPath.row];
if (thisPatient.treatmentName.length > 0) {
cell.textLabel.text = thisPatient.treatmentName;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.textColor = [UIColor blackColor];
} else {
}
if (self.editing) {
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [patients count];
}
#pragma mark UITableViewDelegate Methods
- (void) tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if ( editingStyle == UITableViewCellEditingStyleDelete ) {
[patients removeObjectAtIndex:indexPath.row];
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
LSAppDelegate *delegate = (LSAppDelegate *)[[UIApplication sharedApplication] delegate];
PatientController *patient = [[PatientController alloc] initWithIndexPath:indexPath];
[delegate.navController pushViewController:patient animated:YES];
[tv deselectRowAtIndexPath:indexPath animated:YES];
}
#end
Please say if you want any more code or information and please answer as soon as you can
file for the button I am pushing with:
#import "PatientController.h"
#import "LSAppDelegate.h"
#import "Patient.h"
#import "PRViewController.h"
#interface PatientController ()
#end
#implementation PatientController
- (id)initWithIndexPath:(NSIndexPath *)indexPath {
if ( ( self = [super init]) ) {
index = indexPath;
}
return self;
}
- (IBAction)PatientRecords:(id)sender {
PRViewController *AddPatient = [[PRViewController alloc] initWithIndexPath:indexPath.row];
[self.navigationController pushViewController:AddPatient animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
LSAppDelegate *delegate = (LSAppDelegate *)[[UIApplication sharedApplication] delegate];
Patient *thisPatient = [delegate.patients objectAtIndex:index.row];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.title = thisPatient.patientName;
patientNameView.text = thisPatient.patientName;
patientFirstNameView.text = #"Firstname:";
patientSurnameView.text = thisPatient.patientSurname;
patientSurnameNameView.text = #"Surname:";
patientDoBView.text = thisPatient.patientDoB;
patientDoBDateView.text = #"Date of Birth:";
patientHomeView.text = thisPatient.patientHomeNumber;
patientHomeNumberView.text = #"Home No:";
patientMobileView.text = thisPatient.patientMobileNumber;
patientMobileNumberView.text = #"Mobile No:";
patientAddressView.text = thisPatient.patientAddress;
patientAddressView.editable = NO;
patientAddressPlaceNumberView.text = #"Address:";
patientEmailView.text = thisPatient.patientEmail;
patientEmailAddressView.text = #"Email:";
patientPictureView.image = thisPatient.patientPicture;
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setEditing:(BOOL)editing animated:(BOOL) animated {
if ( editing != self.editing ) {
[super setEditing:editing animated:animated];
patientAddressView.editable = YES;
}
}
#end
Thanks in advance
- (IBAction)PatientRecords:(id)sender {
PRViewController *AddPatient = [[PRViewController alloc] initWithIndexPath:indexPath.row];
[self.navigationController pushViewController:AddPatient animated:YES];
}
This code looks to be the culprit, you're not declaring the variable indexPath anywhere, you need to use index rather than indexpath from what I can see.
Use of undeclared identifyer "indexPath"; did you mean "NSIndexPath"
This error only happen if your do not declare indexPath but try to use it. As Xcode compiler's code sense detect and show you hint that it may be NSIndexPath instead of indexPath. check the use and declaration of indexPath.

Don't see UITableView

My application starts with Root controller called TaskController : UINavigationController as as root view controller of UINavigationController i created class
TaskRootController : UIViewController<UITableViewDelegate> (it has add as view UITableView); When I start application i see only Title form TaskRootController and background color from it. But I don't see table view. If my application starts with TaskRootController as a rootViewController I see table view.
How can I make to see table view in may case ?
PS. Even if I switch TaskRootController to TaskRootController : UITableViewController the behavior is the same.
my code is below:
AppDelegate.m
#implementation AppDelegate
#synthesize window = _window;
#synthesize taskController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.taskController = [TaskController alloc];
self.window.rootViewController = self.taskController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
#end
TaskController.m
#implementation TaskController
#synthesize taskRootController;
- (void) pushInboxController
{
TaskBoxController *taskBoxController = [[TaskBoxController alloc] initWithNibName:nil bundle:NULL];
[self pushViewController:taskBoxController animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self.navigationBar setBarStyle: UIBarStyleBlack];
[self.navigationBar setTranslucent: NO];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.taskRootController = [[TaskRootController alloc] initWithNibName:nil bundle:NULL];
UIViewController *root = self.taskRootController;
[self initWithRootViewController: root];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
[self performSelector:#selector(pushInboxController)];
}
#end
TaskRootController.m
#implementation TaskRootController
#synthesize taskRootView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(#"DUPA");
NSLog(#"SIZE x:%f,y:%f ; %f:%f", self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.bounds.size.height);
self.view.backgroundColor = [UIColor grayColor];
self.title = #"Root";
self.taskRootView = [[UITableView alloc] initWithFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStyleGrouped];
self.taskRootView.delegate = self;
self.taskRootView.dataSource = self;
[self.view addSubview:self.taskRootView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1; // put number for section.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 6; // put number as you want row in section.
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat result = 20.0f;
if([tableView isEqual:self.taskRootView])
{
result = 40.0f;
}
return result;
}
#end
Add this delegate method .
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = #"this is row";
return cell;
}
EDIT :
put init at when you create object of TaskController in AppDelegate.m
self.taskController = [[TaskController alloc]init];
And also put both delegate and datasource to TaskController.h
<UITableViewDataSource, UITableViewDelegate>
and add its relavent methods.
In your AppDelegate
self.taskController = [[TaskController alloc]initWithNibName:#"TaskController" bundle:[NSBundle mainBundle]];
UINavigationController *task = [[UINavigationController alloc] initWithRootViewController:self.taskController];
self.window.rootViewController = task;
In your TaskController
- (void)viewDidLoad
{
[super viewDidLoad];
TaskRootController *tc = [[TaskRootController alloc] initWithNibName:#"TaskRootController" bundle:[NSBundle mainbundle]];
[self addChildViewController:tc];
[tc didMoveToParentViewController:self];
[self.view addSubview:tc.view];
}
Try this ::
set delegate and datasource of your tableview
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [yourArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
cell.textLabel.text = #"row";
return cell;
}
Hope it will help you
in Appdelegate File :-
self.TaskViewController = [[TaskViewController alloc] initWithNibName:#"TaskViewController" bundle:nil];
self.navigationController=[[UINavigationController alloc]initWithRootViewController:self.TaskViewController];
[self.window setRootViewController:navigationController];//ios-6
or
[self.window addSubview:navigationController.view];//<ios-6
Add a Delegate Method in UITableViewDelagates:-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = #"Name";
return cell;
}

Resources