Trying to load a url being passed from the previous viewcontroller in a tabviewcontroller sequence. Checked the usual suspects. UIWebview is added view outlet. All the proper delegate are connected. I'm not sure if the NSURL is being passed to the next view controller as I get a black screen (although the response object isn't nil). It's driving me crazy because it's a simple problem and it's something I've done millions of times but it's not working. Any help would be appreciated.
Below you'll find the code.
SquirrelInformationTableViewController.m
#interface ASAInformationTabViewController (){
NSMutableArray *squirrelArray;
}
#property (nonatomic, strong) ODRefreshControl *refreshControl;
#property (weak, nonatomic) IBOutlet UITableView *squirrelListTableView;
#end
#implementation ASAInformationTabViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setUpSquirrelList];
//Add drag to refresh function
self.refreshControl = [[ODRefreshControl alloc]initInScrollView:self.squirrelListTableView];
self.refreshControl.tintColor = [UIColor colorWithRed:46.0/255 green:172.0/255 blue:247.0/255 alpha:1];
[self.refreshControl addTarget:self action:#selector(dragToRefreshAction:) forControlEvents:UIControlEventValueChanged];
}
-(void)setUpSquirrelList
{
__weak UITableView* weaktable = self.squirrelListTableView;
[[ASASquirrelManager instance] listSquirrels:^(NSString *response, NSMutableArray *result) {
if ([response isEqualToString:CODE_SUCCESS]) {
squirrelArray = result;
dispatch_async(dispatch_get_main_queue(), ^{
if (weaktable) {
[weaktable reloadData];
}
});
}
}];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ASASquirrelInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"squirrelIdentifier"];
ASASquirrelModel *squirrelLocal = squirrelArray[indexPath.row];
cell.squirrelTitleLabel.text = squirrelLocal.title;
cell.squirrelDescLabel.text = squirrelLocal.desc;
NSData *imageData = [[NSData alloc] initWithContentsOfURL:
[NSURL URLWithString:squirrelLocal.image]];
cell.squirrelImage.image = [UIImage imageWithData:imageData];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ASASquirrelModel *squirrelWebLocal = squirrelArray[indexPath.row];
NSString *squirrelURLString = squirrelWebLocal.url;
//create an array with the string you want an access it
NSLog(#"%#", urlStringArray);
//Create a string from the URL pass it to the sdvc.string
SquirrelDetailViewController *sdvc = [SquirrelDetailViewController new];
sdvc.urlString = squirrelURLString;
[self.navigationController pushViewController:sdvc animated:YES];
}
SquirrelDetailViewController.m
#interface SquirrelDetailViewController () <UIWebViewDelegate>
#end
#implementation SquirrelDetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.webView.frame = self.view.bounds;
[self.view addSubview:self.webView];
}
-(void)viewWillAppear:(BOOL)animated
{
self.urlstr = [NSURL URLWithString:self.urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:self.urlstr];
[self.webView loadRequest:requestObj];
}
I think you need to create the instance of the sdvc using storyboard otherwise it will not be getting instantiated properly. So:
SquirrelDetailViewController *sdvc =
(SquirrelDetailViewController *)[[UIStoryboard storyboardWithName:#"XXX" bundle:nil] instantiateViewControllerWithIdentifier:#"YYY"];
where XXX is your storyboard name and YYY is the storyboard identifier for SquirrelDetailViewController.
I found out that the trouble was I wasn't preparing for segue. (hits forehead*)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"webviewpush" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"webviewpush"]) {
// Get destination view
SquirrelDetailViewController *vc = [segue destinationViewController];
NSIndexPath *path = [self.squirrelListTableView indexPathForSelectedRow];
ASASquirrelModel *squirrelWebLocal = squirrelArray[path.row];
NSString *squirrelURLString = squirrelWebLocal.url;
vc.urlString = squirrelURLString;
}
}
If you'll excuse me I'm going to go drown myself now.
Related
I have an array of sounds that populates a TableView. When a user selects one of them, I want to assign that sound to a button in another view controller. That view controller is currently working with a "default" sound that is assigned to the button. What is the best way to do this?
edit I've edited to show my changes, but still doesn't seem to work. Any thoughts?
pickSound.m
#interface pickSound ()
#end
#implementation pickSound
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.titleObjectsArray = #[#"Horn", #"Dog Barking", #"Whistle", #"Funny Noises",];
self.soundObjectsArray = #[#"horn.wav", #"bark1.wav", #"whistle.wav", #"funny.wav",];
// Do any additional setup after loading the view.
}
-(void)viewDidAppear: (BOOL)animated{
[self.navigationController setNavigationBarHidden:NO animated:YES];
[super viewWillAppear:YES];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.titleObjectsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =#"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UIButton *previewSound = [[UIButton alloc]init];
UIImage *btnImage = [UIImage imageNamed:#"PlayButtonPNG.png"];
[previewSound setImage:btnImage forState:UIControlStateNormal];
cell.textLabel.text = [self.titleObjectsArray objectAtIndex:indexPath.row];
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row ==0)
{
sound = #"Horn";
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqual:#"pickedSound"]) {
ViewController *cameraVC = (ViewController *)segue.destinationViewController;
cameraVC.soundId = sound;
}
}
ViewController.m (where button to play sound is located)
#import "ViewController.h"
#import "pictureViewController.h"
#import <AVFoundation/AVFoundation.h>
#interface ViewController ()
#end
#synthesize soundId;
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.soundId = soundId;
if ([soundId isEqualToString:#"horn"]){
NSURL *makeNoiseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"horn" ofType:#".wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)makeNoiseURL, &SoudID);
} else {
NSURL *makeNoiseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"horn" ofType:#".wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)makeNoiseURL, &SoudID);
}
}
- (IBAction)makeNoise:(id)sender {
AudioServicesPlaySystemSound(SoudID);
}
Create an NSString property in your ViewController class and set it when you make a selection in TableView. Remove that hard coded resource loading from viewDidLoad and use this property for resource name.
I figured it out. I created an NSString that is assigned the value of whichever row is selected. Pass that string to the 2nd VC using prepareforsegue. use if statement to assign sound to play to button based on NSString Sound.
**picksound.m **
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedIndexPath = [self.titleObjectsArray objectAtIndex:indexPath.row];
if ([self.selectedIndexPath isEqual:#"Horn"]) {
sound = #"Horn";
} else if ([self.selectedIndexPath isEqual: #"Dog Barking"]) {
sound = #"Dog Barking";
}
[self performSegueWithIdentifier:#"newVC" sender:self];
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
DestinationVC *controller = segue.destinationViewController;
controller.selectedSound = sound;
}
viewcontroller.m
- (IBAction)playSound:(id)sender {
if ([selectedSound isEqualToString:#"Horn"]) {
NSURL *makeNoiseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"horn" ofType:#".wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)makeNoiseURL, &SoudId);
AudioServicesPlaySystemSound(SoudId);
} else if ([selectedSound isEqualToString:#"Dog Barking"]) {
NSURL *makeNoiseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"bark1" ofType:#".wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)makeNoiseURL, &SoudId);
AudioServicesPlaySystemSound(SoudId);
}
}
I have a Master-Detail Application. In there, I've been able to download a XML file and use it as an array.
But I want to choose a tab and have it to play a video.
All of this works except in the following code block.
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
When I try to alloc a MPMoviePlayer, it crashes the program. Any insight would be greatly appreciated.
Code :
MasterViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface MasterViewController : UITableViewController
#property (strong, nonatomic) NSDictionary *presidents;
#property (strong, nonatomic) NSArray *number;
#property (strong, nonatomic) NSArray *name;
#property (strong, nonatomic) NSArray *years;
#property (strong, nonatomic) NSArray *party;
#property (strong, nonatomic) NSArray *image;
#end
MasterViewController.m
#import "MasterViewController.h"
#import "DetailViewController.h"
#interface MasterViewController () {
NSMutableArray *_objects;
}
#end
#implementation MasterViewController
#synthesize number, name, years, party, image;
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
self.navigationItem.title=#"Presidents";
NSString *urlStr = [[NSString alloc]
initWithFormat:#"http://pickupboyd.com/wordpress/wp-content/uploads/2012/04/Presidents12.plist"];
NSURL *url = [NSURL URLWithString:urlStr];
_presidents = [[NSDictionary alloc] initWithContentsOfURL:url];
name = [_presidents objectForKey:#"Names"];
years = [_presidents objectForKey:#"Years"];
party = [_presidents objectForKey:#"Party"];
image = [_presidents objectForKey:#"Images"];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//This is to the get count of the array in dictionary "Presidents" called Number
number = [_presidents objectForKey:#"Number"];
return number.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
NSString *nameOfPresident = [name objectAtIndex:indexPath.row];
cell.textLabel.text = nameOfPresident;
NSString *datesInOffice = [years objectAtIndex:indexPath.row];
cell.detailTextLabel.text = datesInOffice;
//set the image view-------------------------------------
NSString *presidentImages = [image objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:presidentImages];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSURL *movieURL = [party objectAtIndex:indexPath.row];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[[player view] setFrame:[self.view bounds]];
[self.view addSubview:[player view]];
[player play];
MPMoviePlayerViewController *playVideo = [[MPMoviePlayerViewController alloc]initWithContentURL:movieURL];
//NSDate *object = _objects[indexPath.row];
[[segue destinationViewController] presentMoviePlayerViewControllerAnimated:playVideo];
}
}
#end
DetailViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface DetailViewController : UIViewController
#property (strong, nonatomic) id detailItem;
#end
DetailViewController.m
#import "DetailViewController.h"
#interface DetailViewController ()
- (void)configureView;
#end
#implementation DetailViewController
#pragma mark - Managing the detail item
- (void)configureView
{
// Update the user interface for the detail item.
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Try changing this line:
[[player view] setFrame:[self.view bounds]];
To this:
[[player view] setFrame:[self.view frame]];
And see this for the differences between bounds and frame.
Here's the code i use for playing video in a view after a button tap
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController : UIViewController
{
NSURL * videoURL;
UITableView * view;
}
#property (nonatomic, strong) MPMoviePlayerController*player;
-(IBAction)playMovie;
#end
.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)playMovie
{
NSString *url = [[NSBundle mainBundle]
pathForResource:#"testy3 (Converted)" ofType:#"mov"];
self.player = [[MPMoviePlayerController alloc]
initWithContentURL: [NSURL fileURLWithPath:url]];
// Play Partial Screen
self.player.view.frame = CGRectMake(0, 0, 320, 400);
[self.view addSubview:self.player.view];
// Play Movie
[self.player play];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
hi I'm developing a iOS which featuring image updates. For using the NSURLConnectionDelegate and setDatasource to bring the image to tableview with help of php and json now I'm trying give a detail view option for the my table view going as tough time in this can please help me.
the setdatasource coding the imagecell.m
-(void)setDataSource:(image *)inImageObj
{
self.decriptionLabel.text = inImageObj.desp;
NSURL *url = [NSURL URLWithString:inImageObj.img];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
self.responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
{
[self.responseData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
{
UIImage *image = [UIImage imageWithData:self.responseData];
self.thumbImageView.image = image;
}
this is code I used for view the images in table view.m
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *cellIdentifier =#"Cell";
imgpoliticalCell *cell =(imgpoliticalCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell== nil) {
cell = [[imgpoliticalCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
[cell setDataSource:[imgevery objectAtIndex:indexPath.row]];
return cell;
}
now I want view the image and description in the detailviewcontroller. I tried with segue i not able to get it properly
detailviewcontroller.h file
#interface DetailpoliticalViewController : UIViewController
#property (strong,nonatomic) UIImage * image;
#property (strong,nonatomic) NSString * data;
#property (strong, nonatomic) IBOutlet UIImageView *imageview;
#property (strong, nonatomic) IBOutlet UILabel *view;
this is code I have used in the detailviewcontroller.m file
#implementation DetailpoliticalViewController
#synthesize imageview,view;
#synthesize image,data;
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageview.image = self.image;
self.view.text= self.data;
// Do any additional setup after loading the view.
}
And this is the push segue code which I have used in the table view controller
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Detailsegue"]) {
DetailpoliticalViewController *detailvc =(DetailpoliticalViewController *)segue.destinationViewController;
NSIndexPath *indexPath =[self.mytableview indexPathForCell:(UITableViewCell *) sender];
image * eve = [imgevery objectAtIndex:indexPath.row];
[detailvc setDataSource:[imgevery objectAtIndex:indexPath.row]];
}
Now I'm not able to view the image and description in my detail view controller I'm getting the nil exception error
please can any one suggest some way to view the details
thanks in advance
Use
NSIndexPath *indexPath =[self.mytableview indexPathForSelectedRow];
instead of
NSIndexPath *indexPath =[self.mytableview indexPathForCell:(UITableViewCell *) sender];
check this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier: #"DetailSegue" sender: self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"DetailSegue"]) {
DetailpoliticalViewController *detailvc =(DetailpoliticalViewController *)segue.destinationViewController;
indexPath = [self.tableView indexPathForSelectedRow];
image * eve = [imgevery objectAtIndex:indexPath.row];
[detailvc setDataSource:[imgevery objectAtIndex:indexPath.row]];
}
}
Check this tutorial LINK 1
You can do this by implementing this two method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"Detailsegue" sender:indexPath];
}
and below method
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"Detailsegue"]) {
DetailpoliticalViewController *detailvc =(DetailpoliticalViewController *)segue.destinationViewController;
NSIndexPath *indexPath = (NSIndexPath *)sender;
image * eve = [imgevery objectAtIndex:indexPath.row];
[detailvc setDataSource:[imgevery objectAtIndex:indexPath.row]];
}
}
I am new to Ios programming i want to display the data from master view controller into the detail view controller, i am using the master detail template from xcode. the detail array is working it shows the detail in label, how ever i want to display the title as well which is stored in _objects array,
here is my code
#import "MasterViewController.h"
#import "DetailViewController.h"
#interface MasterViewController () {
NSMutableArray *_detailObjects;
NSMutableArray *_thumbnailImage;
}
#end
#implementation MasterViewController
#synthesize _objects;
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title= #"Zodiac List";
_objects = [[NSMutableArray alloc] initWithObjects:
#"value 1",
#"value 2",
#"value 3",
#"value 4",
#"value 5",
,nil];
_detailObjects = [[NSMutableArray alloc] initWithObjects:
#"detail of value 1",
#"detail of value 2",
#"detail of value 3",
#"detail of value 4",
#"detail of value 5",
, nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _objects.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSMutableArray *object = _detailObjects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}
#end
the detail is working fine how ever i want to display the value 1, value 2,value 2 in a label as well..
here is my detail view controller code..
#property (strong, nonatomic) id detailItem;
#property (strong, nonatomic) id detailItemTitle;
#property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
#property (weak, nonatomic) IBOutlet UILabel *zodiacNameLabel;
here is .m file code
#import "DetailViewController.h"
#import "MasterViewController.h"
#interface DetailViewController ()
- (void)configureView;
#end
#implementation DetailViewController
#synthesize zodiacNameLabel;
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
-(void) setDetailItemTitle:(id)detailItemTitle{
if (_detailItemTitle !=detailItemTitle) {
_detailItemTitle = detailItemTitle;
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
// self.zodiacNameLabel.text = [self.]
MasterViewController *master = [[MasterViewController alloc] init];
zodiacNameLabel.text = [master._objects objectAtIndex:0];
}
// if (self.detailItemTitle) {
// self.zodiacNameLabel.text = [self.detailItem description];
// }
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
// MasterViewController *master = [[MasterViewController alloc] init];
// zodiacNameLabel.text = [master._objects objectAtIndex:0];
// MasterViewController *master = [[MasterViewController alloc]init];
// zodiacNameLabel.text = [master._objects objectAtIndex:0]; // you can get first element of an array
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Implement delegate method of tableview which is in your masterviewcontroller and then inside that push your data whatever you want to display in masterviewcontroller like that:-
Assuming that below delegate is in your masterViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_yourController = [[yourController alloc] initWithNibName:#"yourController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:_yourController animated:YES];
}
Now this will alloc, initialize and load your nib into detailviewcontroller and if you want to send message from master to detail then declare property method in detailviewcontroller and just pass it from above like that below:-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_yourDetailController = [[yourDetailController alloc] initWithNibName:#"yourDetailController" bundle:[NSBundle mainBundle]];
[_yourDetailController setTempString:#"test"]; //Assuming that tempString is declared in yourDetailController class
[self.navigationController pushViewController:_yourDetailController animated:YES];
}
Make an array that is "tmpArray" in detailViewController and then you can copied _objects array in to tmpArray. like this
MastrerViewController.m
DetailViewController *detail = [[DetailViewController alloc]init];
detail.tmpArray = [[NSMutableArray alloc] initWithArray:_objects];
DetailViewController.h
#property (nonatomic,retain) NSMutableArray *tmpArray;
I have created a simple rss reader that populates the tableviewcell on viewdidLoad without a problem. My problem is whenever I click my button the tableview doesn't change. I tried reload with the button touchup inside and nothing still happens. Fairly new to Xcode and iOS programming so any help is great.
.m file
#import "ViewController.h"
#import "KMXMLParser.h"
#import "WebViewController.h"
#import "SportsViewController.h"
#interface ViewController ()
#end
#implementation ViewController
{
NSArray *loadData;
NSURL *thumbnails;
}
#synthesize parseResults=_parseResults;
- (void)viewDidLoad
{
[super viewDidLoad];
KMXMLParser *parser = [[KMXMLParser alloc] initWithURL:#"http://www.daytonastate.edu/rss/it.xml" delegate:nil];
_parseResults = [parser posts];
[self refreshFeed];
// Do any additional setup after loading the view, typically from a nib.
}
-(void) refreshInvoked:(id)sender forState:(UIControlState)state
{
[self refreshFeed];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)refreshFeed
{
KMXMLParser *parser = [[KMXMLParser alloc] initWithURL:#"http://www.daytonastate.edu/rss/it.xml" delegate:nil];
_parseResults = [parser posts];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.parseResults.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"DataCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}// Configure the cell...
cell.textLabel.text = (self.parseResults)[indexPath.row][#"title"];
cell.detailTextLabel.text = (self.parseResults)[indexPath.row][#"summary"];
[self reloadData];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
WebViewController *vc = [[WebViewController alloc] init];
vc.url = [NSURL URLWithString:(self.parseResults)[indexPath.row][#"link"] ];
[self.navigationController pushViewController:vc animated:YES];
//Makes sure function clicks to reader feed.
// Navigation logic may go here. Create and push another view controller.
}
-(IBAction)pressBtn:(id)sender
{
UIButton *button= [UIButton buttonWithType:UIButtonTypeRoundedRect];
if (button.tag==1)
{
NSLog(#"Press button 1");
KMXMLParser *parser = [[KMXMLParser alloc] initWithURL:#"http://www.daytonastate.edu/rss/cea.xml" delegate:nil];
_parseResults = [parser posts];
[self reloadData];
}
if (button.tag==2)
{
NSLog(#"Press button 2");
[self EventsBtn:nil];
}
}
- (IBAction)NewsBtn:(id)sender
{
KMXMLParser *parser = [[KMXMLParser alloc] initWithURL:#"http://rss.cnn.com/rss/cnn_topstories.rss" delegate:nil];
_parseResults = [parser posts];
NSLog(#"reload happened");
// self.printMessage = [[PrintHello alloc] init]; // EDIT: THIS LINE WAS MISSING NOW IT WORKS
//[self.printMessage Print];
NSLog(#"NewsBtn Pressed");
}
- (IBAction)SportsBtn:(id)sender
{
KMXMLParser *parser = [[KMXMLParser alloc] initWithURL:#"http://www.daytonastate.edu/rss/it.xml" delegate:nil];
_parseResults = [parser posts];
}
- (IBAction)EventsBtn:(id)sender
{
KMXMLParser *parser = [[KMXMLParser alloc] initWithURL:#"http://www.daytonastate.edu/rss/events.xml" delegate:nil];
_parseResults = [parser posts];
NSLog(#"eventsBtn Pressed");
}
- (IBAction)WeatherBtn:(id)sender
{
KMXMLParser *parser = [[KMXMLParser alloc] initWithURL:#"http://w1.weather.gov/xml/current_obs/KDAB.rss" delegate:nil];
_parseResults = [parser posts];
}
#end
In your pressBtn: method, replace this line:
UIButton *button= [UIButton buttonWithType:UIButtonTypeRoundedRect];
with:
UIButton *button = (UIButton *)sender;
This assumes that in IB you have already hooked up the pressBtn: method to the appropriate button. The code you had was creating a new button when your pressBtn: action was called. Since this new button has a tag value of 0, nothing happened. The code I propose actually makes use of the button that was tapped by the user.
Using the invoker (sender), that is the item which you had action on it. Dont create a new button, you want to check the tag of button so the new button is not the item for your work.
Try your best man, :).