The cell of tavbview quickly slides into a blank - ios

A tabview pull up, load the new data, and then quickly pull up, the above cell disappears and becomes blank,I guess because the refresh time, the data is not with the new
This is the main code:
#interface DYBOrdersViewController ()<UITableViewDelegate,UITableViewDataSource>
#property(nonatomic,strong)NSMutableArray * currentArr;
#property(nonatomic,strong)NSArray * dataArr;
#property(nonatomic,strong)UITableView * mainTab;
#property(nonatomic,strong)UIRefreshControl * refreshC;
#property(nonatomic,assign)BOOL isPull;
#property(nonatomic,assign)CGFloat cellheight;
#end
static NSString * orderID = #"orderID";
#implementation DYBOrdersViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray * mutarr0 = [NSMutableArray arrayWithObjects:#"全部",#"全部",#"全部",#"完成",#"全部", nil];
NSMutableArray * mutarr1 = [NSMutableArray arrayWithObjects:#"待取件",#"待取件",#"待取件",#"待取件", nil];
NSMutableArray * mutarr2 = [NSMutableArray arrayWithObjects:#"未完成",#"未完成",#"未完成", nil];
NSMutableArray * mutarr3 = [NSMutableArray arrayWithObjects:#"已完成",#"已完成", nil];
NSMutableArray * mutarr4 = [NSMutableArray arrayWithObjects:#"已取消", nil];
self.dataArr = #[mutarr0,mutarr1,mutarr2,mutarr3,mutarr4];
self.currentArr = self.dataArr[0];
[self setUI];
self.automaticallyAdjustsScrollViewInsets = NO;
}
// 设置界面
-(void)setUI{
UIRefreshControl * refreshC = [[UIRefreshControl alloc]initWithFrame:self.navBar.bounds];
self.refreshC = refreshC;
[refreshC beginRefreshing];
[refreshC addTarget:self action:#selector(loadData) forControlEvents:UIControlEventValueChanged];
NSArray * segArr = #[#"全部",#"待取件",#"待收货",#"待评价",#"已取消"];
UISegmentedControl * segC = [[UISegmentedControl alloc]initWithItems:segArr];
segC.frame = CGRectMake(0,64, self.view.frame.size.width,40);
segC.tintColor = [UIColor sun_colorWithHex:0x0082f5];
//实现添加的事件
[segC addTarget:self action:#selector(change:) forControlEvents:UIControlEventValueChanged];
// 创建刷新界面
UITableView * tabV = [[UITableView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(segC.frame), [UIScreen mainScreen].bounds.size.width, self.view.frame.size.height - CGRectGetMaxY(segC.frame)-self.tabBarController.tabBar.frame.size.height) style:UITableViewStylePlain];
tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
tabV.showsVerticalScrollIndicator = NO;
tabV.delegate = self;
tabV.dataSource = self;
self.mainTab = tabV;
[tabV registerClass:[DYBOrdersViewCell class] forCellReuseIdentifier:orderID];
[tabV addSubview:self.refreshC];
[self.view addSubview:tabV];
[self.view addSubview:segC];
}
// Refresh data method
-(void)loadData{
[self.refreshC endRefreshing];
[self.currentArr addObject:#"新数据"];
self.isPull = NO;
[self.mainTab reloadData];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100;
}
//点击不同分段就会有不同的事件进行相应
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSLog(#"%lu",(unsigned long)self.currentArr.count);
return self.currentArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
DYBOrdersViewCell * cell = [tableView dequeueReusableCellWithIdentifier:orderID forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// cell.textLabel.text = self.currentArr[indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DYBOrderdetailController * VC = [[DYBOrderdetailController alloc]init];
VC.title = #"订单详情";
VC.view.backgroundColor = [UIColor whiteColor];
[self.navigationController pushViewController:VC animated:YES];
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
// 将要显示的最后一组
NSInteger section = indexPath.section;
// 所有cell数
NSInteger count = [tableView numberOfRowsInSection:section];
//将要显示的row数量
NSInteger row = indexPath.row ;
if (section <0 || row <0) {
return;
}
// 如果是最后一行最后一个cell 数据刷新
if (row == count -1 && !self.isPull) {
NSLog(#"要刷新了");
self.isPull = YES;
[self loadData];
}
}

Related

UITableView unresponsive to gestures and not populating cells with data

I created a UITableView programmatically and set all of its attributes, but the data from my NSMutableArray will not populate the cells and the cells do nothing when tapped. Any insight appreciated, thanks!
Clayton
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
list = [[UITableView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height * .3333, self.view.bounds.size.width, self.view.bounds.size.height * .6667) style:UITableViewStylePlain];
list.delegate = self;
list.dataSource = self;
list.backgroundColor = [UIColor magentaColor];
list.scrollEnabled = YES;
list.userInteractionEnabled = YES;
list.multipleTouchEnabled = YES;
list.hidden = NO;
[self.view addSubview:list];
[self.view bringSubviewToFront:list];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [favorites count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *Cell = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Cell];
}
cell.textLabel.text = [[global sharedInstance].favorites objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor blackColor];
cell.userInteractionEnabled = YES;
cell.hidden = NO;
cell.multipleTouchEnabled = YES;
[self.view bringSubviewToFront:cell];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"selected %ld row", (long)indexPath.row);
}
Got it thanks, the problem was with the data transferring from my singleton array of favorites to my local array (which was previously empty). Much obliged :)
At the end of viewDidLoad method, just add this:
[list reloadData];

UITableViewController resetting data source

I have a UITableViewController that is presented as the view controller of a UIPopOverController. The tvc has three properties - a dictionary and two arrays. The dictionary holds two arrays, which are used to populate the other two properties. I follow this process:
In root view controller I init the table view controller
On a trigger I set the dictionary property of the table view controller and call a method (reloadData).
- (void) reloadData {
self.arrGroupSearches = [self.dictSavedSearches objectForKey:#"Group Searches"];
self.arrCustomerSearches = [self.dictSavedSearches objectForKey:#"Customer Searches"];
[self.tableView reloadData];
}
as I step through the method it the data is brought in as I expected.
self SavedSearchesPopoverViewController * 0x786653c0 0x786653c0
UITableViewController UITableViewController
_dictSavedSearches NSDictionary * 2 key/value pairs 0x79fb6ab0
_arrGroupSearches NSArray * #"1 object" 0x79fb6b00
_arrCustomerSearches NSArray * #"0 objects" 0x79faf410
but once the code hits [self.tableView reloadData] call, it resets the viewcontroller properties
self SavedSearchesPopoverViewController * 0x786653c0 0x786653c0
UITableViewController UITableViewController
_dictSavedSearches NSDictionary * 0 key/value pairs 0x79938560
_arrGroupSearches NSArray * #"0 objects" 0x78744160
_arrCustomerSearches NSArray * #"0 objects" 0x78744160
I'm not really sure what I am doing wrong here.
Edit: Here's the whole implementation:
#implementation SavedSearchesPopoverViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.arrCustomerSearches = [[NSArray alloc] init];
self.arrGroupSearches = [[NSArray alloc] init];
self.dictSavedSearches = [[NSDictionary alloc] init];
self.tableView.rowHeight = 30.0;
}
- (void) reloadData {
self.arrGroupSearches = [self.dictSavedSearches objectForKey:#"Group Searches"];
self.arrCustomerSearches = [self.dictSavedSearches objectForKey:#"Customer Searches"];
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView* vHeader = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, tableView.frame.size.width, 40.0)];
if (section == 0) {
UILabel* lblPopoverTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 5.0, 240.0, 30.0)];
lblPopoverTitle.text = #"Group Saved Searches";
lblPopoverTitle.textColor = GMT_BRIGHT_BLUE;
lblPopoverTitle.font = FORM_NAME;
lblPopoverTitle.textAlignment = NSTextAlignmentCenter;
[vHeader addSubview:lblPopoverTitle];
} else if (section == 1) {
UILabel* lblPopoverTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 5.0, 240.0, 30.0)];
lblPopoverTitle.text = #"Customer Saved Searches";
lblPopoverTitle.textColor = GMT_BRIGHT_BLUE;
lblPopoverTitle.font = FORM_NAME;
lblPopoverTitle.textAlignment = NSTextAlignmentCenter;
[vHeader addSubview:lblPopoverTitle];
}
vHeader.backgroundColor = GMT_DARK_BLUE;
return vHeader;
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40.0;
}
- (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.
if (section == 0) {
return self.arrGroupSearches.count;
} else if (section == 1) {
return self.arrCustomerSearches.count;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSString* strValue;
if (indexPath.section == 0) {
strValue = [self.arrGroupSearches objectAtIndex:indexPath.row];
} else if (indexPath.section == 1) {
strValue = [self.arrCustomerSearches objectAtIndex:indexPath.row];
}
cell.textLabel.text = strValue;
cell.textLabel.textColor = GMT_DARK_BLUE;
cell.textLabel.font = TABLE_CELL_FONT;
return cell;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary* dictUserData = [[NSDictionary alloc] initWithObjectsAndKeys:
nil];
[[NSNotificationCenter defaultCenter] postNotificationName:#"cvc" object:self userInfo:dictUserData];
}
The view controller is init in another view controller (contentViewController) in the view did load:
self.mySavedSearchesPopover = [[SavedSearchesPopoverViewController alloc] init];
and presented in the popover like so:
if (showSavedSearches) {
//check to see if there are saved searches first before presenting popover
NSDictionary* dictSavedSearches = [self.myController readPlistFile:#"savedSearches"];
if (![dictSavedSearches objectForKey:#"Error Message"]) {
self.mySavedSearchesPopover.dictSavedSearches = [self.myController getSavedSearches:dictSavedSearches];
[self.mySavedSearchesPopover reloadData];
[self.mySavedSearchesPopover.tableView reloadData];
[self presentPopover:SAVED_SEACHES_POPOVER];
} else {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"savedSearchErrorTitle", nil) message:NSLocalizedString(#"savedSearchErrorMsg", nil) delegate:nil cancelButtonTitle:NSLocalizedString(#"ok", nil) otherButtonTitles:nil, nil];
[alert show];
}
}
- (void) presentPopover : (int) popoverID {
if (self.currentPopoverController != nil) {
[self.currentPopoverController dismissPopoverAnimated:YES];
self.currentPopoverController = nil;
}
CGRect launchFrame;
...
} else if (popoverID == SAVED_SEACHES_POPOVER) {
//this is inited in the update view method
launchFrame = CGRectMake(0.0, 70.0, 0.0, 180.0);
self.currentPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.mySavedSearchesPopover];
self.currentPopoverController.popoverContentSize = CGSizeMake(240.0, 300.0);
...
//display popovercontroller
[self.currentPopoverController presentPopoverFromRect:launchFrame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];
In the following code block where you present the popover:
[self.mySavedSearchesPopover reloadData];
[self.mySavedSearchesPopover.tableView reloadData];
[self presentPopover:SAVED_SEACHES_POPOVER];
The viewDidLoad method is firing after you call [self.mySavedSearchesPopover reloadData] which is recreating those properties with empty arrays. You need to call reloadData after you present the popover.

tableview doesn't see the title for header in section method

I was trying to create a custom viewForHeaderInSection for my tableview.Tableview itself
works fine, but for some reason, compiler skips,
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{}
Delegate method, and I tried what is written on the reference , and this .But for some reason it just doesn't read these methods. Obviously, I am doing something wrong. If someone can point my mistake out, I would appreciate. Thank you in advance.
#import "TableViewController.h"
#interface TableViewController ()
#end
#implementation TableViewController
#synthesize settingTableView,audioPlayer,labelSwitch,descriptiveSwitch,autoPlaySwitch;;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.settingTableView.tableFooterView = [[UIView alloc]init];
self.settingTableView.scrollEnabled = NO;
settings = #{#"Animation Sets" : #[#"Set1",#"Set2",#"Set3"],#"Settings" : #[#"Label",#"Sound",#"Autoplay"]};
values = [[settings allKeys]sortedArrayUsingSelector:#selector(localizedStandardCompare:)];
[settingTableView setRowHeight:44];
[settingTableView reloadData];
}
-(void)close:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
[self.delegate closeView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [values count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [values objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSString *sectionTitle = [values objectAtIndex:section];
NSArray *sectionValue = [settings objectForKey:sectionTitle];
return [sectionValue count];
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
CGRect frame = tableView.frame;
NSString *value = [values objectAtIndex:section];
UILabel *title = [[UILabel alloc]init];
UIView *headerView = [[UIView alloc]init];
//if (section == 0 && section == 1) {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0")) {
title.frame = CGRectMake(10,10,150,30);
}
else
{
title.frame = CGRectMake(10,5,100,30);
}
title.backgroundColor = [UIColor clearColor];
title.text = value;
headerView.frame = CGRectMake(0,0,frame.size.width,frame.size.height);
headerView.backgroundColor = [UIColor clearColor];
[headerView addSubview:title];
[headerView setBackgroundColor:[UIColor blueColor]];
//}
return headerView;
[settingTableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = nil;
static NSString *MyCellIdentifier = #"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyCellIdentifier];
cell.textLabel.numberOfLines = 2;
cell.textLabel.font = [UIFont fontWithName:#"Helvetica" size:17.0];
NSString *sectionTitle = [values objectAtIndex:indexPath.section];
NSArray *sectionValue= [settings objectForKey:sectionTitle];
NSString *settingValues = [sectionValue objectAtIndex:indexPath.row];
cell.textLabel.text = settingValues;
return cell;
}
}
You need to make sure that the class that implements that delegate method is the delegate and dataSource of your table view.

UILabel showing wrong

i'm using a tableview to load datas from my college db, the table load the tablecell normally... but when i scroll down the table the name of the discipline goes well but the grade is showing up one on top of above
why is that?
#import "NFMainViewController.h"
#import "NFData.h"
#interface NFMainViewController ()
#end
#implementation NFMainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
data = [[NFData getData] objectForKey:#"data"];
cursoData = nil;
cursosView = [[UIViewController alloc] init];
[cursosView setTitle:#"Cursos"];
cursosTable = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[cursosTable setDelegate:self];
[cursosTable setDataSource:self];
[cursosView.view addSubview:cursosTable];
[self pushViewController:cursosView animated:NO];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - TableView delegates
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == cursosTable) {
return [data count];
} else {
return [cursoData count];
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static NSString *ident = #"headerIdent";
UITableViewHeaderFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:ident];
if (view == nil) {
view = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:ident];
}
if (tableView == cursosTable) {
view.textLabel.text = [[data objectAtIndex:section] objectForKey:#"unidade"];
} else {
NSDictionary *temp = [cursoData objectAtIndex:section];
view.textLabel.text = [NSString stringWithFormat:#"%#º/%#", [temp objectForKey:#"semestre"], [temp objectForKey:#"ano"]];
}
return view;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == cursosTable) {
return [[[data objectAtIndex:section] objectForKey:#"cursos"] count];
} else {
return [[[cursoData objectAtIndex:section] objectForKey:#"disciplinas"] count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *ident = #"cellIdent";
UITableViewCell *view = [tableView dequeueReusableCellWithIdentifier:ident];
if (view == nil) {
view = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ident];
}
if (tableView == cursosTable) {
view.textLabel.text = [[[[data objectAtIndex:indexPath.section] objectForKey:#"cursos"] objectAtIndex:indexPath.row] objectForKey:#"curso"];
} else {
UIFont *font = [UIFont fontWithName:#"Arial" size:10.0f];
view.textLabel.font = font;
view.selectionStyle = UITableViewCellSelectionStyleNone;
NSDictionary *temp = [[[cursoData objectAtIndex:indexPath.section] objectForKey:#"disciplinas"] objectAtIndex:indexPath.row];
view.textLabel.text = [temp objectForKey:#"disciplina"];
CGRect notaRect = view.bounds;
notaRect.origin.x = notaRect.size.width - 70.0f;
notaRect.size.width = 50.0f;
UILabel *nota = [[UILabel alloc] initWithFrame:notaRect];
nota.textAlignment = NSTextAlignmentRight;
nota.font = font;
nota.text = [temp objectForKey:#"nota"];
[view addSubview:nota];
CGRect labelRect = view.textLabel.frame;
labelRect.size.height -= 60;
view.textLabel.frame = labelRect;
CGRect progRect = view.bounds;
progRect.origin.x += 6.0f;
progRect.size.width -= 12.0f;
progRect.origin.y += progRect.size.height - 6.0f;
progRect.size.height = 5.0f;
UIProgressView *prog = [[UIProgressView alloc] initWithFrame:progRect];
int faltas = [[temp objectForKey:#"faltas"] intValue];
int maximo = [[temp objectForKey:#"maximo"] intValue];
float value = 1.0f * faltas / maximo;
if (value > 1.0f) {
prog.progressTintColor = [UIColor blackColor];
} else if (value == 1.0f) {
prog.progressTintColor = [UIColor redColor];
} else if (value >= 0.7f) {
prog.progressTintColor = [UIColor yellowColor];
}
[prog setProgress:value];
[view addSubview:prog];
}
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == cursosTable) {
cursoData = [[[[data objectAtIndex:indexPath.section] objectForKey:#"cursos"] objectAtIndex:indexPath.row] objectForKey:#"epocas"];
notasView = [[UIViewController alloc] init];
[notasView setTitle:#"Disciplinas"];
notasTable = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[notasTable setDelegate:self];
[notasTable setDataSource:self];
[notasView.view addSubview:notasTable];
[self pushViewController:notasView animated:YES];
}
}
#end
Your nota UILabel is created each time a UITableViewCell is dequeued. So the first time the tableview loads everything is fine. Then when you start scrolling, your code reuse cells with the nota label already created, but you add another label on top of it. You need to reuse the label previously created.
The best way is to create a UITableViewCell subclass with a nota property for instance.

UITableView clicking on an item an opening a new screen/view/activity

I have a table view(HomeViewController) consisting of items as:
locations
Reporting
Setting
I am having these items as separate files(LocationViewController,ReportingView Controller and Setting ViewController).Now if user clicks on location a new screen/activity/view should be open and same for rest items.
Can some one please help.my code is as:
#import "HomePageController.h" #implementation HomePageController
#synthesize menuList, table;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
menuList=[[NSMutableArray alloc] initWithObjects:
[NSArray arrayWithObjects:#"LOCATIONS",nil],
[NSArray arrayWithObjects:#"REPORTING",nil],
[NSArray arrayWithObjects:#"SETTINGS",nil],
[NSArray arrayWithObjects:#"PASSWORD",nil],
[NSArray arrayWithObjects:#"HELP",nil],
[NSArray arrayWithObjects:#"ABOUT",nil],
[NSArray arrayWithObjects:#"SHARE",nil],
nil];
[self.navigationController setNavigationBarHidden:NO];
self.navigationController.navigationBar.tintColor=[UIColor blackColor];
self.navigationController.navigationBar.barStyle=UIBarStyleBlackTranslucent;
self.title=#"CoinRead";
[table reloadData];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 40;
}
- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section{
return menuList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"CellIdentifier";
UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero] autorelease];
}
cell.highlighted=NO;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSArray *rowArray = [menuList objectAtIndex:indexPath.row];
UILabel *nameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(15, 8, 200, 20)]autorelease];
nameLabel.text = [NSString stringWithFormat:#"%#",[rowArray objectAtIndex:0]];
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.shadowColor=[UIColor whiteColor];
nameLabel.shadowOffset=CGSizeMake(0.0, 0.5);
nameLabel.textColor = RGB(0,0,0);
[nameLabel setFont:[UIFont boldSystemFontOfSize:16.0f]];
[cell.contentView addSubview:nameLabel];
return cell;
}
Implement below method of UITableViewDelegate to get the selection event
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Resources