Grouped styled tableview in detailview of splitview - ipad

I try to have a grouped styled tableview in the right view of my splitview (DetailViewController). The DetailViewController has a UITableViewController without NIB file. I already have implemented
- (id)initWithStyle:(UITableViewStyle)style {
if ((self = [super initWithStyle:UITableViewStyleGrouped])) {
}
return self;
}
With no effect. Maybe I have to override -(id)init{}?
Any help would be nice. regards Christian

Yeah, I just solved it. In MainWindow-iPad.xib I put an UITableViewController on the spot of the UIViewController of the right panel. With this controller comes a Tableview. First i switched the name of the class to DetailViewController. Then I linked all outlets and delegates. Finally I set the style to grouped of this tableview in IB. And that worked.

Related

Tableview to another viewcontroller

I have a controller named as "firstViewcontroller" where i have a UITableView named as "discoveredInstanceTableView". I want to load that UITableView in to another UIViewController named as "secondViewcontroller"
I have used the below code but it is not working, It says property "discoveredInstanceTableView" not found ...Anybody please help me:
In the firstViewcontroller:
IBOutlet UITableView *discoveredInstanceTableView;
In the Secondviewcontroller:
firstViewcontroller *vc1 = [[firstViewcontroller alloc]initWithNibName:#"firstViewcontroller" bundle:nil];
[self addChildViewController:vc1];
[self.myTableview addSubview:vc1.discoveredInstanceTableView];
What you asked is valid only if you curious to know why the above thing is not working answer would be
You are doing something that is not allowed, this can not be done as per the documentation.
However, If we forget about the right wrong approach, you probably adding a table view as a subview over a table view itself and I am sure you passing a table view to a table view which might not be allocated.
First think about the UITableView how it works? it simply a ScrollableView which display content over its cells.
Eventually would recommend you read about TableView
EDIT: From the Above Comments
IMPORTANT: You should not embed UIWebView or UITableView objects in
UIScrollView objects. If you do so, unexpected behavior can result
because touch events for the two objects can be mixed up and wrongly
handled.» As UITableView is a UIScrollView, this applies here as well.
Possible Alternatives of displaying TableView inside the SecondViewController
Use #Rajath Kornaya's Answer And In my opinion that is not right approach since whenever you required callback action like on cell tap, you want to display an alert(or something else), you can't get the delegate callback inside the SecondViewController
But there are so many other right approaches available, that you should follow up.
Create a TableView separately either programmatically or through the XIB/Storyboard
Add delegate and data source (methods which responds when something interesting happened e.g Cell going to populate called cellForRowAtIndexPath) to current SecondViewController
Define all required data source methods and write proper code.
If you required to do something on cell tap, add specific delegate method too.
But if you want to reuse the FirstViewController Class TableView simply create a CustomView and add TableView inside there and simply add that view to each view controller class.
I hope it may helps you!!!
declare in viewcontroller2
#property (nonatomic, strong) UITableView *table;
create table in viewcontroller1
tableView=[[UITableView alloc]initWithFrame:CGRectMake(10, 10, 250, 300) style:UITableViewStylePlain];
[self.view addSubview:tableView];
tableView.backgroundColor=[UIColor greenColor];
while calling viewcontroller2 pass table to viewcontroller2
ViewController2 *v2=[[ViewController2 alloc]init];
v2.table=tableView;
UINavigationController *navigation=[[UINavigationController alloc]initWithRootViewController:v2];
[self presentViewController:navigation animated:YES completion:nil];
in viewcontroller2 access the table using the global variable
[self.view addSubview:self.table];

ViewDidLoad not called on custom objects in Storyboard

I finally made the switch to Storyboards and i am having issues loading custom controllers which was pretty easy to do when using interface builder.
I have ViewControllerOne with two components: A UIView and UITableView as the subview.
I want the UITableView to be controlled by a custom tableview controller. If this was Interface builder i would have dropped a tableview controller onto the XIB, linked to the custom controller and made the connections and it would have been done.
Using storyboard, i don’t believe its possible to drop a UIViewController/UITableViewController onto a scene which already has a view controller, i relied on Objects to achieve this.
So i added a Object onto the scene and linked it to my custom tableview controller. I set up delegate/date source for my UITableView to point to the custom controller. I finally connected the UITableViews outlet to the custom controller.
When i compile this, the custom controllers delegate (for the table view) gets called but the viewDidLoad is never called.
The only way i can invoke viewDidLoad is if i move the UITableView out of ViewControllerOne. My understanding was that even though there is one view controller for a scene i can still manipulate the subviews using custom controllers.
Am i misunderstanding something or is there is a solution for this ?
Some screenshots
There is a bit of magic in that. Call self.view from awakeFromNib and flow will back to the rails
- (void)awakeFromNib
{
[super awakeFromNib];
// here comes the magic - call self.view and view will load as expected
NSLog(#"awakeFromNib %#", self.view)
}
you can call it from initWithNibName:bundle:
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(#"awakeFromNib %#", self.view);
}
return self;
}
the point is to call self.view because apparently something is done inside.
If I have understood your question correctly:
1 Open the storyboard and navigate to the table view controller that you would like to be of your custom type.
2 Click on the identity inspector in the right hand side panel.
3 Set the class to what it should be.

TableView overlaps the status bar in sliding view controller

I'm creating a slidingView controller using ECSlidingViewController like the one the previous version of Facebook had. Everything works fine but the menuViewController (tableViewController) is being overlapped by the status bar when I add an image to cell like shown below. Does anyone know how to fix it.
it's works 100%
- (void)viewDidLoad
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0")) {
[self.tableView setContentInset:UIEdgeInsetsMake(20, self.tableView.contentInset.left, self.tableView.contentInset.bottom, self.tableView.contentInset.right)];
}
[super viewDidLoad];
// Initialize table data
}
Use this to set tableview frame
[self.tableView setFrame:CGRectMake(self.tableView.frame.origin.x, 20, self.tableView.frame.size.width,self.tableView.frame.size.width)];

UITableViewController hold by a UINavigationController

My aim is to make a UITableView with a certain level of navigation. All I will be using are table views so I really want to go with UITableViewController and UINavigationController.
I created a subclass of UITableViewController, here is the xib file:
It's automatically generated as the class is UITableViewController subclass. Is it enough to get a navigation bar, or should I add something on the xib.
And the relevant code in the .m file is the following:
- (void)viewDidLoad
{
[super viewDidLoad];
UITableViewController *tableViewController=[[UITableViewController alloc]initWithNibName:#"ViewController" bundle:nil];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:tableViewController];
self.view.window.rootViewController=navController;
//Create the modal for the UITableView
array1=[NSArray arrayWithObjects:#"Categorie 1",#"Categorie 2",#"Categorie 3",#"Categorie 4",#"Categorie 5",#"Categorie 6",#"Categorie 7",#"Categorie 8",#"Categorie 9",#"Categorie 10", nil];
}
And here is what I got:
I was waiting to see a navigation bar at the top of the view. I know I am missing something, so please bear with me and give help. Thanx.
In your MainWindow.xib, you have to drag a UINavigationController, then a UITableViewController. Set the class of the UITableViewController to your table view controller subclass. Also make sure that the table view controller is set as the root of the navigation controller.

Tabbar Item connected to ibaction

I am trying to find a way to make an item of the TabBar acting as a "UIbutton".
I would like when pressing to this item just make it work as a ibaction method.
I tried several implementation as :
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
}
But I was not able to get the method working.
What will be the best solution to fake an item function of a tabbar, and make it open an UIActionSheet for example ?
Try using an IBOutlet and UITabBarDelegate in your viewController.
#interface MyViewController : UIViewController <UITabBarDelegate> {
IBOutlet UITabBar* tabBar;
}
#end
Connect the UITabBar to that IBOutlet in Interface Builder.
Set the delegate to 'self' in your viewController's viewDidLoad method:
-(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
tabBar.delegate = self;
}
And set up the delegate method with some way to differentiate the tabs:
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSLog(item.title);
if([item.title isEqualToString:#"some label"]) {
// do something for this specific button
}
}
(This is an old post, but I had the same question. Hopefully this saves someone else the same trouble.)
You can try the tabBarController shouldSelectViewController delegate method. Override this. Return NO on the tab you want to display an ActionSheet from, and instead instantiate the ActionSheet in this method.
You'll be required to have a placeholder UIViewController in place of this tab.
As mentioned above, this goes against Apple HIG and might be reason for your app to be rejected.
Check this out! These people create a tabBar with a uibutton in it! http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/
Full source code:
https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar
I tried the code some time ago and it worked for me.
Call your action method in the viewDidLoad method of the view of the tab bar item selected.

Resources