Xcode: How to switch to another window using TableView? - xcode

the error ---> when i click the name the application crashes...
rectification---> when i click the name in table it should jump to another view...
my code is
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[ListArr objectAtIndex:indexPath.row];
ListData *oList = [[ListData alloc] initWithNibName:#"ListData" bundle:nil];
NSString *psCatId = [NSString stringWithFormat:#"%d",indexPath.row+1];
oList.psId = psCatId;
[self presentModalViewController:oList animated:YES];
[oList release];
}

Related

How to push new view from TableViewCell?

In my app I am trying to navigate to a new View from a TableViewCell, But i dont know how. Could you help guys? I am using Xcode 4.6. and .xib, no storyboard. I am very new to coding so please explain it as simple as possible! Here is what i have tried, please correct me:
- (void)viewDidLoad
{
tableData = [[NSArray alloc] initWithObjects:#"aaoversikt1", #"Paul", #"George", #"Ringo", nil];
[super viewDidLoad];
UILabel *nav_title1 = [[UILabel alloc] initWithFrame:CGRectMake(60, 10, 220, 25)];
nav_title1.font = [UIFont fontWithName:#"Arial-BoldMT" size:18];
nav_title1.textColor = [UIColor whiteColor];
nav_title1.adjustsFontSizeToFitWidth = NO;
nav_title1.textAlignment = NSTextAlignmentCenter;
nav_title1.text = #"Ă…lesund";
nav_title1.backgroundColor = [UIColor clearColor];
self.navigationItem.titleView = nav_title1;
}
#pragma mark - TableView Data Source methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section;
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *cell = nil;
static NSString *CellIdentifier = #"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - TableView Delegate methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AAOversiktViewController *aaoversikt1 = [[AAOversiktViewController alloc] initWithNibName:#"AAOversiktViewController" bundle:nil];
[self.navigationController pushViewController:aaoversikt1 animated:YES];
}
Thank You!
From first glance I would say that the problem lies within your [self.navigationController pushViewController] method. Have you initiated a navigation controller in your app either in the app delegate or root view controller?
If not i would recommend:
[self presentViewController:aaoversik1 animated:YES completion:NULL];
If you are wanting to push through the navigation stack so that you have a back button then I would look at implementing a UINaviationController.
Otherwise you can create a custom back button and use the same method in this post to present the root view controller (not totally recomended as using UINavigationController is much cleaner).
Let me know if this has been of any help, T

Xcode parsing RSS XML with images issue

I am trying to parse text with images in the UITableView and I can only see the text for every line but I can't see the images.
Here is my code;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [self.anaTablo dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel *textBaslik = (UILabel *) [cell viewWithTag:3];
UIImage *imagePic = (UIImage *) [cell viewWithTag:7];
textBaslik.text =[titleArray objectAtIndex:indexPath.row];
imagePic.images = [imageArray objectAtIndex:indexPath.row];
return cell;
}
but it didn't works and after searching I have tried this to;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
UILabel *textBaslik = (UILabel *) [cell viewWithTag:3];
UIImage *imagePic = (UIImage *) [cell viewWithTag:7];
textBaslik.text =[titleArray objectAtIndex:indexPath.row];
NSString *str1 = [[NSString alloc] initWithFormat:#"%#", imageArray];
NSData *bgImageData = [NSData dataWithContentsOfFile:str1];
UIImage *img1 = [UIImage imageWithData:bgImageData];
imagePic = [img1 objectAtIndex:indexPath.row];
return cell
}
Am I doing something wrong? I am kind new to Xcode
Thanks from now.
I check you code and i change the following
NSString *str1 = [[NSString alloc] initWithFormat:#"%#", imageArray];
NSData *bgImageData = [NSData dataWithContentsOfFile:str1];
UIImage *img1 = [UIImage imageWithData:bgImageData];
imagePic = [imageArray objectAtIndex:indexPath.row];
cell.imageView.image=imagePic;
in the delegate method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Now a new error appear, check it
Check this tutorial about parsing RSS with XMLParses, it works perfectly.
Wiki XML parse data
You should check this sample code using TBXML framework
TBXML parser

How do I access UITableView section label from didSelectRowAtIndexPath

In my tableView didSelectRowAtIndexPath I can access the cell textLabel. How do I access the section label?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
topPlacesAppDelegate *appDelegate = (topPlacesAppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.chosenPhoto = [self.topPlaces objectAtIndex:indexPath.row];
. . .
UITableViewCell *mycell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(#" indexPath.section / Row = %i / %i", indexPath.section, indexPath.row);
NSLog(#" textLabel.text = %#", mycell.textLabel.text);
NSLog(#" detailTextLabel.text = %#", mycell.detailTextLabel.text);
[self performSegueWithIdentifier:#"Show Site Table" sender:nil];
}
It sounds like you are looking for the table section header. I don't think you can read or otherwise access that data. But you can set it with the method on the UITableViewDataSource:
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
Details are described here:
Change UITableView section header/footer WHILE RUNNING the app?

mwfeedpaser detailview

I just started using xcode and OBJ-c this year.
I am using mwfeedparser for a app I'm making but would like to change the look of the detailview.
right now i'm using the demo app that came with mwfeedparser to change the detail view.
i would like the detail view to have labels instead of being a tableview
i have changed this code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detail = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
detail.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detail animated:YES];
// Deselect
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
when i run the code the detailview doesn't even come up. am I doing something wrong?
thanks for your help.
btw when i do get this done I'll put it up on github incase anybody else needs it
enter code hereself.parsedItems = [[NSMutableArray alloc] init];
- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item{
if (item) {
[self.parsedItems addObject:item];
}
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detail = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
detail.item = [self.parsedItems objectAtIndex:indexPath.row];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detail animated:YES];
}

NSTableView with plist file

I am very new to mac app development. so just doing some practical exercise.
I want to create a tableview which display data from my plist file.
I have one windowcontroller class and window controller.xib file.
I drag and drop NSTableView to the .xib file.
and using this code to load plist file
- (void)windowDidLoad
{
[super windowDidLoad];
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:#"tenth" ofType:#"plist"];
file = [[NSArray alloc] initWithContentsOfFile:path];
}
Now what should i do for displaying rows in my tableview??
Which method i have to use? and how??
like in IOS development we are using
- (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] autorelease];
}
NSArray *temp = [file objectAtIndex:indexPath.row];
cell.textLabel.text = [temp objectAtIndex:0];
return cell;
}
You can use either bindings with an NSArrayController or implement the NSTableViewDataSource protocol.
Recommended reading: Table View Programming Guide.

Resources