I'm trying to incorporate XLMailBox, Custom ViewController as a parent viewController that can switch between different childViewController using a TabBar.
I'm loading a Custom UITableViewController
called SwipeTableViewController as a childViewController within a parent viewController
I use this code to load the ParentViewController in AppDelegate as RootViewController:
#implementation SwipeTableAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
SwipeTableViewController * child_1 = [[SwipeTableViewController alloc] initWithStyle:UITableViewStylePlain];
NSArray * childViewControllers = #[child_1];
XLSwipeContainerController * containerController = [[XLSwipeContainerController alloc] initWithViewControllers:childViewControllers];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:containerController];
return YES;
}
The SwipeTableViewController loads the table view as follows:
- (void)viewDidLoad
{
[super viewDidLoad];
patternImages = [NSMutableArray arrayWithObjects:#"neon-autumn.gif", #"alchemy.jpg", #"white-wood.jpg", #"green-goblin.png", #"subway-lines.png", #"canvas-orange.jpg", #"kiwis.png", #"cuadros.png", #"hodgepodge.png", #"naranjas.png", #"bunting-flag.png", nil];
self.title = #"Rounds";
_patients = [RND_PatientDB loadScaryBugDocs];
[self.tableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:#"Cell"];
NSLog(#"FirstViewController - viewDidLoad");
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self action:#selector(addTapped:)];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"Cell";
CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
RND_Patient *patients = [self.patients objectAtIndex:indexPath.row];
cell.patternImageView.image = [UIImage imageNamed:[patternImages objectAtIndex:indexPath.row]];
cell.patternLabel.text = patients.data.ptName;
cell.ptDesc.text = patients.data.ptDesc;
cell.ptNumber.text = patients.data.ptNumber;
if (patients.data.completed == 1){
cell.backgroundColor = [UIColor greenColor];
}
return cell;
}
It then configures the cell using the CustomTableViewCell class and populates with data from RND_Patients mutablearray which it loads initially.
Now my problem is that when I load the SwipeTableViewController as a childViewController, the cells are empty and are not populated with data.
When I load directly the SwipeTableViewController as part of the RootViewController without using the XLMailBox custom navigation controller, the table view loads just fine and has the appropriate cells and the appropriate data.
I do not understand the discrepancy between these two views. All my code seems correct, but in my first example, the CustomTableViewCell does not load and in the second it loads. Any ideas on how can I fix this?
Related
I have a regular view controller (not a table view controller) and on that view I have a tableview. My table view cells are custom and I just made them through storyboards (didn't do anything in the code) but when I run my application, the tableview is blank. Any ideas as to why tho is happening to me? I have looked at other things on here but all of these other scenarios have to do with the person using an NSArray to fill out the tableview in the code, but mine is custom so I am not doing that. Thanks for any help. And before you mark this duplicate, please actually read this.
my code is as follows:
#interface TTViewController ()
{
NSArray *messageComponents;
}
#end
#implementation TTViewController
#synthesize dateTimePicker, messageSetupTableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.title = #"Message Setup";
messageComponents = [[NSArray alloc] initWithObjects:#"Recipient",#"Message", #"Date",#"haha", nil];
messageSetupTableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
messageSetupTableView.alpha = 0.9;
}
#pragma mark -
#pragma mark Table view data source
-(NSInteger) numberOfSectionsInTableView:(UITableView *) tableView{
return [messageComponents count];
}
-(NSInteger)tableView:(UITableView *) tableVew numberOfRowsInSection:(NSInteger)section{
return 1;
}
// Customize the appearance of table view cells.
- (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];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
}
}
// Configure the cell.
cell.textLabel.text = [messageComponents objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[messageComponents objectAtIndex:indexPath.row]];
cell.backgroundColor = [UIColor redColor];
cell.textLabel.textColor = [UIColor whiteColor];
UIColor *selectedColor = [UIColor blueColor];
UIView *myBackgroundColor = [[UIView alloc] init];
[myBackgroundColor setBackgroundColor:selectedColor];
[cell setSelectedBackgroundView:myBackgroundColor];
return cell;
I want my table view to have a date picker in one section, a textview in the other, and a button and a few text fields in the other. Thanks
A couple of suggestions:
First make sure that UITableView's delegate and datasource are mapped or not either from IB or programmatically.
Put a break point on cellForRowAtIndexPath delegate function and see if it comes in this functions, and make sure you are using this function to create your custom cells.
Double check your have at least one row in your tableView using something similar:
- (NSInteger)numberOfRowsInSection:(NSInteger)section
{
return 5; // for test pass value 5 so tableView should aware to display 5 rows.
}
Hope it helps!
I have a UITableView and another view. The other view has a UITextView that I want populated with different text depending on what row in the table view is selected. I know how to do it if I create different views for all of the different text options. If I did it that way, I could just have that view open when the row is tapped. I'm just wanting to avoid having to create a bunch of different views and just use one that gets loaded with different text depending on row tapped in the table view. I guess I just need to know how the view with the text view can access indexPath.row from the table view. Any suggestions?
EDIT: Here is my code.
LHRRoster.m
#import "LHRRoster.h"
#import "CustomCellBackground.h"
#import "OnMyHonor.h"
#import "AVA.h"
#import "Receivers.h"
#import "BandDetailView.h"
#interface LHRRoster ()
#end
#implementation LHRRoster
{
NSMutableArray *mbTableData;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
mbTableData = [NSMutableArray arrayWithObjects:#"Aesthetics Versus Architecture", #"On My Honor", #"Receivers", #"Skyscraper Stereo", #"California", #"Late Ones", #"Uh-Huh Baby Yeah", #"Danielle Bouchard", #"Chris Karrer", #"Joey Blue", #"The Codas", #"Your Favorite Hero", #"Nixon", #"Skam Impaired", #" SaySomethingHugeOnFire", #"Adore Me Not", #"Common Collective", #"The Royal Tees", #"The Gravetones", #"Bush League", #"Rock & Roll Television", #" Tastyface", #"The Lips", #"Mercy Academy", #"Audiostrobelight", nil];
self.title = #"LHR Roster";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [mbTableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *mbTableIdentifier = #"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mbTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mbTableIdentifier];
cell.textLabel.font=[UIFont systemFontOfSize:14.0];
}
cell.backgroundView = [[CustomCellBackground alloc] init];
cell.selectedBackgroundView = [[CustomCellBackground alloc] init];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.highlightedTextColor = [UIColor darkGrayColor];
cell.textLabel.text = [mbTableData objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
BandDetailView *detailView = [[BandDetailView alloc]initWithNibName:#"BandDetailView" bundle:nil];
if (indexPath.row == 0)
{
detailView.title = #"Aesthetics vs Architecture";
UIImage *image = [UIImage imageNamed: #"AVA.png"];
[detailView.bandPic setImage:image];
NSString *bio = #"";
[detailView.bandInfo setText:bio];
[self.navigationController pushViewController:detailView animated:YES];
}
}
#end
You are getting the selected cell object, just pass that object to the TextView and it will dynamically load selected cell data.An important thing to note,first push view controller then pass data to that controller.In your code you have passed data first,then pushed view controller, that doesnt work
MVC - model, view, controller. Your data is model. The table view and the text view are view. Your UIViewController is the controller. It does all the work.
Implement didSelectRowAtIndexPath in the controller, which is the delegate of the table view. Now you know that a row of the table was selected, and you know which row it is. So pull the desired text out of your model and stick it in the UITextView.
Expand your didSelectRowAtIndexPath to also modify your UITextView.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
**myUiTextView.text = somethingBasedOnTheRowSelected[indexPath.row];** <-- new code here
// followed by your existing code
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
BandDetailView *detailView = [[BandDetailView alloc]initWithNibName:#"BandDetailView" bundle:nil];
if (indexPath.row == 0)
{
detailView.title = #"Aesthetics vs Architecture";
UIImage *image = [UIImage imageNamed: #"AVA.png"];
[detailView.bandPic setImage:image];
NSString *bio = #"";
[detailView.bandInfo setText:bio];
[self.navigationController pushViewController:detailView animated:YES];
}
**myUiTextView.text =[yourarray indexPath.row];
}
follow this code this code might help you.
Just Add your code is
yourtextfieldname.text=[yourarrayname objectAtIndex:indexpath.row];
and get your selected row textfield data in your textfield.
i hope this code is useful for you .
Hi This is my first iPad app and trying to port my iphone app to iPad.
I have followed all the tutorials from http://www.raywenderlich.com/ still having a problem.
Also review this question and still having the problem . Splitviewcontroller with two tableviews, delegate problem
Basically, I have two UITableViewControllers in SplitViewController and when I click the tableview cell in root view controller, I want to populate the details in DetailsViewController in Right side on another Tableview.
The problem is I can manage to pass the array data from but I can't call tableview reload method.
Here is the code
LeftViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
if (row == 0){
NSLog(#"Row 0 Pressed");
RightViewController *rightvc = [self.storyboard instantiateViewControllerWithIdentifier:#"displayenglish"];
_locallayleft = [ConversationDatabase database].conversationsInfos;
NSLog(#"Just pushed the array");
rightvc.detailItem = _locallayleft;
rightvc.title = #"Greetings";
}
else if (row == 1) {
NSLog(#"Row 1 Pressed");
RightViewController *rightvc = [self.storyboard instantiateViewControllerWithIdentifier:#"displayenglish"];
_locallayleft = [ConversationDatabase database].conversationsInfosgeneral;
rightvc.detailItem = _locallayleft;
rightvc.title = #"General Conversation";
}
-----------------------------------------------------------------------------------------
RightViewController
- (void)setDetailItem:(NSArray *)newDetailItem
{
if(_detailItem != newDetailItem) {
_detailItem = newDetailItem;
[self configureView];
}
}
- (void)configureView
{
if (self.detailItem) {
self.locallay = self.detailItem;
_listOfCoversation = [[NSMutableArray alloc] init];
for (ConversationInEnglish *c in _locallay)
{
NSString *english = c.english;
NSLog(#"setDetails Item get called");
NSLog(#"%#",english);
[_listOfCoversation addObject:english];
}
[self.tableView reloadData];
NSLog(#"Trying to reload TableView");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureView];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_locallay count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"English";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
ConversationInEnglish *con = _locallay [indexPath.row];
_englishLabel = (UILabel *) [cell viewWithTag:200];
_englishLabel.text = con.english;
NSLog(#"My data from cell %#",con.english );
[_englishLabel setFont:[UIFont fontWithName:#"Open Sans" size:22]];
_myanmarLabel = (UILabel *) [cell viewWithTag:300];
[_myanmarLabel setFont:[UIFont fontWithName:#"TharLon" size:17]];
_tonebasedLabel = (UILabel *) [cell viewWithTag:400];
_tonebasedLabel.text = con.tone_based;
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"tableviewcell.png"]];
self.tableView.backgroundColor = background;
return cell;
}
It looks like when you tap a row in the table on the left, instead of updating the table on the right, you're instantiating a whole new table from the storyboard instead, but not replacing the one on the right with it.
There isn't enough context here to say exactly how to fix it, but what you'd want to do is when you tap a row in the table on the left, update the table on the right by setting its detailItem property.
You'll need access to the other table view. There are a few ways to do this depending on how you've got your application set up - if you're using the same left table view on both the iPhone and iPad then you'll probably need some conditional code to locate it, for example:
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
DetailViewController *detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
detailViewController.detailItem = newDetailItem;
}
Or you could configure it through the storyboard. Either way, the key is to find and update the existing table view instead of instantiating a new one from the storyboard.
I have created a tableview with the data from an array. Now i want the details for all the rows of the tableview. If i select any recipe from the tableview it should show me all the ingredients and procedure to prepare that recipe with a pic of that particular recipe on top. I am new to this field so kindly help.
Here's "ViewController.m"
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
RecipeList = [[NSMutableArray alloc]init];
[RecipeList addObject:#"Chicken Kabab"];
[RecipeList addObject:#"Chicken Tikka"];
[RecipeList addObject:#"Chicken 65"];
[RecipeList addObject:#"Chicken Do Pyaza"];
CGRect frame = self.view.frame;
RecipeTable = [[UITableView alloc]initWithFrame:frame style:UITableViewStylePlain];
RecipeTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
RecipeTable.backgroundColor = [UIColor cyanColor];
RecipeTable.delegate = self;
RecipeTable.dataSource = self;
[self.view addSubview:RecipeTable];
[RecipeTable setScrollEnabled:YES];
[RecipeTable setUserInteractionEnabled:YES];
[RecipeTable setRowHeight:35];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return #"RECIPES";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return RecipeList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
cell.textLabel.text = [RecipeList objectAtIndex:indexPath.row];
return cell;
}
#end
Just pass recipe name to the detailViewController. Then depending on the name of the recipe you can load the suitable image in UIImageView.
In the code recipename is an NSString in detailViewController. Declare it as a property..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
NSString *name=[recipe objectAtIndex:indexPath.row];
detailViewController.recipename=name;
[self.navigationController pushViewController:detailViewController animated:YES];
}
Then in the detaiViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
if([recipename isEqualToString:#"Pizza"])
{
UIImage *image = [UIImage imageNamed: #"pizza.png"];
[img setImage:image];
}
else if([recipename isEqualToString:#"Chicken 65"])
{
UIImage *image = [UIImage imageNamed: #"chicken.png"];
[img setImage:image];
}
}
you must use the DidSelectRow Delegate of UITableView . Then if you select a recipe it calls the DidSelectRow delegate .Inside this delegate you do the coding for pushing to a new ViewController . Create an UIImageView on top of your new ViewController , then pass the image from your TableViewCell to the UIImageView of your new viewController
If you want the details of a particular Dish populated in another ViewController that is pushed, the easiest way is by creating an NSObject with all the details required for that particular dish and maintaining it as an array. When you select a row in tableView, the didSelectRowAtIndexPath: get the object at that indexPath and pass it to the next VC which is being pushed. In the detail VC you can populate the details with that from the object.
Instead of doing like this
RecipeList = [[NSMutableArray alloc]init];
[RecipeList addObject:#"Chicken Kabab"];
do something like
RecipeList = [[NSMutableArray alloc]init];
[RecipeList addObject:dishObj];
where dishObj is an NSObject, of Class Dish which contains Dish name, image and recipe.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
Dish *dishObject = [RecipeList objectAtIndex:indexPath.row];
cell.textLabel.text = dishObject.dishName;
return cell;
Try this ,
you must use the DidSelectRow Delegate of UITableView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
NSString *strDishName = [RecipeList objectAtIndex:indexPath.row];
detailViewController.strDishDetail =strDishName;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
I hope the following tutorial will useful for u..Segue
I have a Navigation Controller embedded in a RootViewController. The elements present inside the RootViewController are a segmented control and a UIView. As the different segments are selected, the UIView displays a corresponding ViewController.
Now each of the ViewController being displayed in the UIView is a UITableViewController.
I need to display the table values as per the segment selections. And also if any of the row of the table is selected, it has to move to a newer ViewController with the detailed view.
I am able to display the UITableViewControllers as per the segment change. However, when i click on the row of the table, the newer ViewController that comes up is blank (Black Screen) even though I have created the particular ViewController in the Storyboard and set up an identifier as well.
Code for the Segmented Control change in ViewController.m
- (void)segmentedControlChangedValue:(UISegmentedControl*)segmentedControl {
int selIndex = segmentedControl.selectedIndex;
if (selIndex == 0)
{
aTable = [[aTableViewController alloc] init];
aTable.view.frame = self.myView.bounds;
[self.myView addSubview:aTable.view];
[self addChildViewController:aTable];
}
if (selIndex == 1)
{
bTable = [[bTableViewController alloc] init];
bTable.view.frame = self.myView.bounds;
[self.myView addSubview:bTable.view];
[self addChildViewController:bTable];
}
if (selIndex == 2)
{
//NSLog (#"Well you selected a 3rd option");
}}
Code for the didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
newDetailController* newController = [self.storyboard instantiateViewControllerWithIdentifier:#"Detail"];
newController = [[newDetailController alloc] init];
[[self navigationController] pushViewController:newController animated:YES];}
The pushViewController pushes an empty view for me even though I have specified the ViewController to use in the Storyboard design and also using an identifier.
Please help me in understanding what I must do to rectify this error.
UPDATE - The above problem has been resolved.
The problem I face now is being unable to access the data in the newViewController.
I pass the data to the newViewController as follows:
Create a class named newClass which contains all the elements I want to pass across.
Create a NSMutableArray "newObjects" in the firstViewController.
Create each newClass object at this method.
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *CellIdentifier = #"Cell";
customBigTableCell *cell = (customBigTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[customBigTableCell alloc] init];
}
cell.name.text = [object objectForKey:#"objName"];
newClass* newObj = [[newClass alloc] init];
newObj.objName = cell.name.text;
[newObjects addObject:newObj];
return cell;
}
Pls pardon me .. for the indenting with the code block is messed up...
Also the PFObject is cos i use Parse for database.
Add the created object to the newObjects array.
In the - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method, this is the code
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
newDetailController* newController = [storyboard instantiateViewControllerWithIdentifier:#"UpcomingDetail"];
obj = [[newClass alloc] init];
NSIndexPath* path = [self.tableView indexPathForSelectedRow];
obj = [newObjects objectAtIndex:path.row];
NSLog(#"Row selected is %ld", (long)path.row); //this returns the correct row selected
NSLog(#"Movie selected is %#", [[newObjects objectAtIndex:path.row] objName]);//however this is not the right one as per the cellForRowAtIndexPath method.
[newController setNewObj:obj];
[[self navigationController] pushViewController:newController animated:YES];
}
When I run this code, the row is selected correctly. However I dont get the corresponding row in the database. The array gets stored with redundant data.
You need to get rid of that middle line:
newController = [[newDetailController alloc] init];
That just redefines newController (as an empty controller with no view set up), which you defined in the first line.