After a table view cell is clicked, in the next controller it is removed from the list of item - xcode

I do not really have much idea how to get this done but the idea is that in the first view controller, it will have an array of 6 items. After any of the table view cell is clicked, that particular cell will be removed and the next controller will display the remaining 5 items.
in the FirstController .m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
SecondController *sc = [sb instantiateViewControllerWithIdentifier:#"SecondController"];
filteredFive = [[NSMutableArray alloc] init];
// I only display two of it here as it will be very lengthy
if ([[totalItems objectAtIndex:indexPath.row] isEqual:#"ONE"]) {
[filteredFive addObject:#"TWO"];
[filteredFive addObject:#"THREE"];
[filteredFive addObject:#"FOUR"];
[filteredFive addObject:#"FIVE"];
[filteredFive addObject:#"SIX"];
}
if ([[totalItems objectAtIndex:indexPath.row] isEqual:#"TWO"]) {
[filteredFive addObject:#"ONE"];
[filteredFive addObject:#"THREE"];
[filteredFive addObject:#"FOUR"];
[filteredFive addObject:#"FIVE"];
[filteredFive addObject:#"SIX"];
}
[self.navigationController pushViewController:sc animated:NO];
// this is the part I am trying to transfer the array filteredFive into SecondController's array
sc.fiveItems = filteredFive;
Then at SecondController.h
#interface SecondController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSMutableArray *fiveItems;
}
#property (weak, nonatomic) IBOutlet UITableView *secondTable;
#property (nonatomic, retain) NSMutableArray *fiveItems;
#end
SecondController.m
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [fiveItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.textLabel.text = [fiveCourses objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
I am wondering if there is any errors in my codes that I have that disallow the data to be shown. Is it that I failed to transfer the array from one to another? Or am I missing some code thus the code is not showing in the SecondController?
If there is another way to display the 5 remaining items, I will be willing to try too.

Related

IOS 7 Xcode Search Bar Controller Implementation

Sunny Thank you for your reply. I made the following changes and now by clicking on a tablecell or search result, I am pushed to DetailViewController but, for any cell I click on I get the same DetailView. I need the detail view to show different information depending on the cell I click on.
I added this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
[self performSegueWithIdentifier: #"ShowDetails" sender: self];
}
}
New segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"ShowDetails"]) {
DetailViewController *detailviewcontroller = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
int row = [myIndexPath row];
detailviewcontroller.DetailModal = #[_Title[row],_Attribute[row]];
}
}
update:
The reason I am having difficulty in implementing your code is because my information to be passed to the detailview is in DetailViewController.h but as an array not a string:
#property (nonatomic,strong) NSArray *Title;
#property (nonatomic,strong) NSArray *Attribute;
in the viewdidload I get these from my plist:
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
_Title = [dict objectForKey:#"caseName"];
_Attribute= [dict objectForKey:#"attribute"];
the table view is populated with said data with the following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TableViewCell";
TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView)
{
cell.textLabel.text = [self.searchResult objectAtIndex:indexPath.row];
}
else
{
cell.TitleLabel.text = self.Title[indexPath.row];
cell.AttributeLabel.text = self.Attribute[indexPath.row];
}
return cell;
}
Then in the DetailViewController.h:
#property (strong, nonatomic) IBOutlet UILabel *TitleLabel;
#property (nonatomic,strong) IBOutlet UILabel *AttributeLabel;
#property (nonatomic,strong) NSArray *DetailModal;
DetailViewController.m:
_TitleLabel.text = _DetailModal[0];
_AttributeLabel.text = _DetailModal[1];
My segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"ShowDetails"]) {
DetailViewController *detailviewcontroller = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
int row = [myIndexPath row];
detailviewcontroller.DetailModal = #[_Title[row],_Attribute[row]];
}
}
I thought it would help to put more of my code so you're able to get clearer picture. In my non expert opinion, I think the reason your code doesn't work for me is because my data is being stored in an array (DetailModal) and not in a string.
Thank you for taking the time to help me with this
You should implement TableView delegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (tableView == self.searchDisplayController.searchResultsTableView) {
[self performSegueWithIdentifier:kSHOW_DETAILS sender:cell];
}
else {
[self performSegueWithIdentifier:kSHOW_DETAILS sender:cell];
}
}
Update:
You have to set the value to be displayed in the detailed view. You might declare a property in the header file for your detailView which you might set in prepareForSegue (or in the didSelectRowAtIndexPath above). For example, in DetailViewController you might do this:
#interface DetailViewController: UIViewController
#property (weak, nonatomic) NSString *myDetailValue;
#end
Then in tableView: didSelectRowAtIndexPath: above, set the correct value before you do the segue:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (tableView == self.searchDisplayController.searchResultsTableView) {
// TODO select value from filteredList to set the detailViewController, e.g.:
self.detailedViewController.myDetailValue = valueFromFilteredListForIndexPath;
[self performSegueWithIdentifier:kSHOW_DETAILS sender:cell];
}
else {
// TODO select value from regular list to set the detailViewController, e.g.:
self.detailedViewController.myDetailValue = valueFromRegularListForIndexPath;
[self performSegueWithIdentifier:kSHOW_DETAILS sender:cell];
}
}
Similarly, you can do it the prepare for segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"ShowDetails"]) {
DetailViewController *detailviewcontroller = [segue destinationViewController];
NSIndexPath *myIndexPath;
if (self.inSearch) {
myIndexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
detailedViewController.myDetailValue = valueFromFilteredListForIndexPath;
}
else {
myIndexPath = [self.tableView indexPathForSelectedRow];
detailedViewController.myDetailValue = valueFromRegularListForIndexPath;
}
}
}

TableView code to display plist is not working, Is it because it has to be on a UITableView Controller? (Xcode)

I cannot get my plist to display on my app. I need to use TableView and not a TableView Controller. Im not sure if I have followed the wrong code when first attempting it. Please take a look.
m. file is:
#import "ECSlidingViewController.h"
#import "NewsFeedViewController.h"
#import "BuySharesViewController.h"
#import "SellSharesViewController.h"
#import "FinancesViewController.h"
#import "CurrentHoldingsViewController.h"
#import "TradingHistoryViewController.h"
#import "LeaderboardViewController.h"
#import "HowToPlayViewController.h"
#import "MenuViewController.h"
#import "InitViewController.h"
#interface SellSharesViewController ()
{
BOOL isSearching;
}
#property (nonatomic, readonly) NSDate *CurrentDate;
#property (nonatomic, strong) NSDictionary *shares;
#property (nonatomic, strong) NSArray *shareValue;
#property (nonatomic, strong) NSArray *number;
#property (nonatomic, strong) NSArray *shareName;
- (void)resetSearch;
- (void)handleSearchForTerm:(NSString *)searchTerm;
#end
#implementation SellSharesViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
isSearching = NO;
NSString *path=[[NSBundle mainBundle] pathForResource:#"shares" ofType:#"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.allNames = dict;
//NSArray *array = [[self.names allKeys] sortedArrayUsingSelector:#selector(compare:)];
//self.keys = (NSMutableArray *)array;
[self resetSearch];
[self.table reloadData];
[self.table setContentOffset:CGPointMake(0.0, 44.0) animated:NO];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (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 ([self.keys count] > 0) ? [self.keys count] : 1 ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if ([self.keys count] == 0)
return 0 ;
NSString *key = [self.keys objectAtIndex:section];
NSArray *nameSection = [self.names objectForKey:key];
return nameSection.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [self.keys objectAtIndex:section];
NSArray *nameSection = [self.names objectForKey:key];
cell.textLabel.text = [nameSection objectAtIndex:row];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if ([self.keys count] == 0)
return nil;
NSString *key = [self.keys objectAtIndex:section];
if (key == UITableViewIndexSearch)
return nil;
return key;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[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;
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
if (isSearching)
return nil;
return self.keys;
}
#pragma mark -
#pragma mark Custom Methods
- (void) resetSearch {
NSMutableDictionary *allNamesCopy = [self.allNames mutableDeepCopy];
self.names = allNamesCopy;
NSMutableArray *keyArray = [[NSMutableArray alloc] init];
[keyArray addObjectsFromArray:[[self.allNames allKeys]
sortedArrayUsingSelector:#selector(compare:)]];
[keyArray insertObject:UITableViewIndexSearch atIndex:0];
self.keys = keyArray;
}
- (void)handleSearchForTerm:(NSString *)searchTerm {
NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
[self resetSearch];
for (NSString *key in self.keys) {
NSMutableArray *array = [self.names valueForKey:key];
NSMutableArray *toRemove = [[NSMutableArray alloc] init];
for (NSString *name in array ) {
if ([name rangeOfString:searchTerm
options:NSCaseInsensitiveSearch].location == NSNotFound)
[toRemove addObject:name];
}
if ([array count] == [toRemove count])
[sectionsToRemove addObject:key];
[array removeObjectsInArray:toRemove];
}
[self.keys removeObjectsInArray:sectionsToRemove];
[self.table reloadData];
}
#pragma mark -
#pragma mark Table View Delegate Methods
- (NSIndexPath *)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.search resignFirstResponder];
isSearching = NO;
self.search.text = #"";
[self.table reloadData];
return indexPath;
}
#pragma mark -
#pragma mark Search Bar Delegate Methods
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSString *searchTerm = [searchBar text];
[self handleSearchForTerm:searchTerm];
}
- (void)searchBar:(UISearchBar *)searchBar
textDidChange:(NSString *)searchTerm {
if ([searchTerm length] == 0) {
[self resetSearch];
[self.table reloadData];
return;
}
[self handleSearchForTerm:searchTerm];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
isSearching = NO;
self.search.text = #"" ;
[self resetSearch];
[self.table reloadData];
[searchBar resignFirstResponder];
}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
isSearching = YES;
[self.table reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView
sectionForSectionIndexTitle:(NSString *)titleForHeaderInSection
atIndex:(NSInteger)index {
NSString *key = [self.keys objectAtIndex:index];
if (key == UITableViewIndexSearch) {
[tableView setContentOffset:CGPointZero animated:NO];
return NSNotFound;
}
else {
return index;
}
}
#end
h.file is:
#import <UIKit/UIKit.h>
#interface SellSharesViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UITableView *sellShares;
#property (weak, nonatomic) IBOutlet UILabel *rowSelectedDisplay;
#property (weak, nonatomic) IBOutlet UIButton *removeShare;
#property (strong, nonatomic) UIButton *menuBtn;
-(IBAction)removeShareButton:(id)sender;
#end
Feel free to ask for anything else that may help. Thanks.
Change the uitableview property to strong instead of weak. I do this to have a strong pointer to the tableview so it does not get deallicateded. Also you need to connect the delegate and datasource of the uitableview to the uiviewcontroller in the storyboard. So the protocol methods will be called in your uiviewcontroller. If they are not connected the protocol methods are not being called so nothing will show up in your table view.
If you have an array of dictionaries the fornumberofrows return [myarray count];
Connecting the datasource and delegate in the storyboard is overlooked a lot of times so check this first. I hope this helps!
Did you set Delegate and Datasource in the XIB?
Other things you need to check is ,
Put break point in below methods and check if it s firing
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Make sure you are not returning zero in the first two methods.
If either of first 2 methods are not firing then it means you did not added the datasource in XIB

Using a UIpickerview in a xib file

i have created a xib file in Xcode 4.2 and i am looking at getting it to the tabbed application but i have been trying and I'm a little bit new to Xcode , coding so thats why i need your help i have my code below but there are a few little errors but what i would like you lot to help me with is maybe getting to a tabbed application... well telling me what to do anyhow. heres a video for you to have a look at in case i haven't explained it correct (this is my video i did just for this question http://www.youtube.com/watch?v=e7R5_kGClM0 hope the video help but more importantly you can help me.
There is the .h but the is no errors in this
#import <UIKit/UIKit.h>
#interface myview : UIViewController <UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource>
#property (strong, nonatomic) IBOutlet UITableView* tableView;
#property (strong, nonatomic) IBOutlet UIPickerView* pickerView;
#property (strong, nonatomic) NSMutableArray* tableData;
#property (strong, nonatomic) NSMutableArray* pickerData;
#end
This is the .m but i will break it up
#import "myview.h"
#implementation myview
#synthesize tableView, pickerView, tableData, pickerData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
this is the -(void)viewDidLoad];etc..
- (void)viewDidUnload
{
[super viewDidUnload];
tableView.delegate = self;
tableView.dataSource = self;
pickerView.delegate = self;
pickerView.dataSource = self;
tableData = [[NSMutableArray alloc] init]; // table starts empty
pickerData = [[NSMutableArray alloc] initWithObjects:#"1", #"2", #"3", #"4", #"5", nil]; // picker starts with values 1, 2, 3, 4, 5
[tableView reloadData];
[pickerView reloadAllComponents]; // Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(bool)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
//The number of sections in UITableView
return 1;
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
// The number of rows in the UITableView
return [tableData 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];
}
// Set the table cell text to the appropriate value in tableDate
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Whatever happens when you select a table view row.
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
// The number of sections in the UIPickerView
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
// The number of rows in the UIPickerView
return [pickerData count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
// The data for each row in the UIPickerView
return [pickerData objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// whatever you want to happen when a row is selected.
// here I am assuming you want to remove from the picker and add to the table on selection
[tableData addObject:[pickerData objectAtIndex:row]];
[pickerData removeObjectAtIndex:row];
[tableView reloadData];
[pickerView reloadAllComponents];
}
#end
Here Are The Errors In The Code There are Two
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
^^^^^^^^^^^^^^^^^
**Local declaration of 'tableView hides instance variable**
Second error
[pickerView reloadAllComponents];
^^^^^^^^^^^^^^
Local declaration of 'pickerView hides instance variable
Thanks Very Much I Hope To Here From You Soon !!!
Use this, "tableView hides instance variable" occurs if local variable and instance variable have the same name.
- (UITableViewCell*)tableView:(UITableView*)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [ [UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
and for pickerView use this
[self.pickerView reloadAllComponents];

Cell configuration method

Am having some trouble configuring table cell in an array. Have commented out the errors returned by the LLVM compiler.
Implementation file:
#import "BIDFirstLevelController.h"
#import "BIDSecondLevelViewController.h"
#implementation BIDFirstLevelController
#synthesize controllers;
- (void) viewDidLoad
{
[super viewDidLoad];
self.title = #"First Level";
NSMutableArray *array = [[NSMutableArray alloc]init];
self.controllers = array;
}
- (void) viewDidUnload
{
[super viewDidUnload];
self.controllers = nil;
}
#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.controllers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *FirstLevelCell = #"FirstLevelCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FirstLevelCell];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FirstLevelCell];
}
}
// Configure the cell
NSUInteger row = [indexPath row]; // replace with NSUIndexPath
BIDSecondLevelViewController *controller = [controllers objectAtIndex:row]; //replace controllers with controller
cell.textLabel.text = controller.title; // unknown type name 'cell', Expected identifier or '('
cell.imageView.image = controller.rowImage; // Expected identifier or '(
cell.accessoryType = UITableViewAccessoryDisclosureIndicator; // Unknown type name 'cell'
return cell;
}
#pragma mark -
#pragma mark Table View Delegate Methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{NSUInteger row = [indexPath row];
BIDSecondLevelViewController *nextController = [self.controllers objectAtIndex:row];
[self.navigationController pushViewController:nextController animated:YES];
#end
Interface file:
#import <UIKit/UIKit.h>
#interface BIDFirstLevelController : UITableViewController
#property (strong, nonatomic) NSArray *controllers;
#end // Unexpected '#' in program
You need to delete a curly brace after your if statement your tableView:cellForRowAtIndexPath: should look like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *FirstLevelCell = #"FirstLevelCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FirstLevelCell];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FirstLevelCell];
}
// DELETE THE } THAT IS HERE
// Configure the cell
NSUInteger row = [indexPath row];
BIDSecondLevelViewController *controller = [controllers objectAtIndex:row];
cell.textLabel.text = controller.title;
cell.imageView.image = controller.rowImage;
cell.accessoryType = UITableViewAccessoryDisclosureIndicator;
return cell;
}
You also need to add a curly brace to close your final function:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row = [indexPath row];
BIDSecondLevelViewController *nextController = [self.controllers objectAtIndex:row];
[self.navigationController pushViewController:nextController animated:YES];
} // This curly brace is missing
#end

Grouped Table View

New to Xcode,
I have created a grouped table view,containing different amounts of rows in each section and I now do not know the best way to populate the cells with data then move on to the next view when the cell is pressed.
Please Help.
Thank you
you could try out this basic tutorial to see how you can populate your table..
http://blog.webscale.co.in/?p=150
and for performing action when a cell is pressed, you would basically need to do something like this in the didSelectRowAtIndexPath method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if( 0 == indexPath.row)
{
NSLog(#"first row selected");
if(patientView == nil)
patientView = [[PatientList alloc]init];
[self.navigationController pushViewController:patientView animated:YES];
}
This is just a very very basic example of what you want to do... playing a bit around with this would help you learn more...
**set in .h file**
#property(nonatomic, retain)NSArray *data;
#property(nonatomic, retain)NSArray *sections;
**in .m file view did load**
self.sections = [[NSArray alloc] initWithObjects:#"university",#"sabaragamuwa",#"Srilanka",nil];
self.data = [[NSArray alloc]initWithObjects:
[[NSArray alloc] initWithObjects:
#"CiS",
#"006",
#"07", nil],
[[NSArray alloc] initWithObjects:
#"cis",
#"006",
#"007", nil],
[[NSArray alloc] initWithObjects:
#"cis",
#"006",
#"07", nil],nil];
**addthoose**
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return [self.sections count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return [self.sections objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [data count];}
**addalsooo**
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
// Configure the cell...
if (cell == nil){
// Create the cell.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier];
}
NSArray* dataArray = [data objectAtIndex:indexPath.section];
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
cell.textLabel.textAlignment = UITextAlignmentRight;
cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:139.0/255.0 blue:69.0/255.0 alpha:1.0];
UIImage *cellImage = [UIImage imageNamed:#"oranimCellIco.png"];
cell.imageView.image = cellImage;
return cell;}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray* dataArray = [data objectAtIndex:indexPath.section];
NSString *catgory= [dataArray objectAtIndex:indexPath.row];
if(catgory==#"cis")
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Answer Set"
message:#"Answer set as Yes Or No"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
else if(catgory==#"006")
{
answerviewcon *vc1=[self.storyboard instantiateViewControllerWithIdentifier:#"answerviewcon"];
[self presentViewController:vc1 animated:YES completion:nil];
}

Resources