I have a main menu. Where we can find some buttons to different Function.
I used ModalTransition to switch between views, so I didn't use NavController.
One function is a TableView, then detailview.
On the .xib, I can't move the TableView, and when I'm on my simulator on my tableview, I can't go back, because the tableview take all the screen.
I'd like to Resize the tableview to add a Navigation bar and custom my own button.
How I can do it ?
You can set UITableView frame yourself -
[tableView setFrame:CGRectMake(0.0, 44.0, 416.0, 320.0)];
User UiTableView frame property to achieve your goal
Declare the tableview as IBOutlet
.h
interface MyViewController : UIViewController {
IBOutlet UITableView *myTableView;
}
#property (nonatomic, retain) IBOutlet UITableView *myTableView;
.m
#synthesize myTableView;
Then open .Xib and connect myTableView with you .Xib table
Then Resize the table view
self.myTableView.frame = CGRectMake(0, 0, 320, 200); // assign you frame here
or Try to add the UITable through programatically..Take a look the below code
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100); style:UITableViewStylePlain];
[self.view addSubview:tableView];
tableView.delegate = self;
tableView.dataSource = self;
[tableView reloadData];
Related
I have a TableViewController which should have a "floating" header at the top of the table view which should not scroll with the content.
Is there a way to achieve this using a UITableViewController (I know this could be done with nested a Tableview inside a plain UIViewController but I would prefer to have a UITableViewController as the main ViewController so I can use the benefits of Storyboard TableView-Goodies.
Make a nib with a UITableViewController or a subclass of it and simply rearrange the table view to make room for the header view. A table view controller with a slightly different layout and more views is still a table view controller.
It might be considered a hack, but this seems to do the job! (tested with the default Master-Detail project template)
First change the type of the MasterViewController to a UIViewController and add the protocol references for the delegate and datasource. Also add an IBOutlet for a UITableView.
#interface MasterViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#end
Next, wire up that IBOutlet to the UITableView in the Storyboard editor.
Now add the following code to viewDidLoad:
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
UILabel *header = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
header.text = #"HEADER";
header.backgroundColor = [UIColor greenColor];
[mainView addSubview:header];
self.tableView.frame = CGRectMake(0, 40, 320, 440);
[mainView addSubview:self.tableView];
self.view = mainView;
I'm new to iPhone development. I have so many UIImageViews added as subview at runtime to the self.view.
My current architecture is:
Inside UIView there is a UIScrollView and inside UIScrollView there is another UIView which is attached to a UIView sub class named SeatingPlan.
SeatingPlan only draws the grid on the screen.
The UIImageViews are drawn on the screen the by UIViewController sub class named SeatingPlanViewContoller. The UIImageViews are added as the subviews.
The UIImageViews are saved in an NSMutableArray.
The .h file:
#interface SeatingPlanViewController : UIViewController <UIScrollViewDelegate, UIAlertViewDelegate>{
IBOutlet UIScrollView * scrollView;
SeatingPlan * planView;
CGPoint origin;
NSMutableArray * arrayOfImages;
}
The .m file:
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationItem setTitle:#"Seating Planner"];
UIBarButtonItem *mySave = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:#selector(Save)];
self.navigationItem.rightBarButtonItem = mySave;
[mySave release];
segmentController.selectedSegmentIndex = UISegmentedControlNoSegment;
segmentController.momentary = YES;
scrollView.contentSize=CGSizeMake(1280.0,960.0);
[scrollView setBackgroundColor:[UIColor whiteColor]];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
[planView addSubview:scrollView];
[self.view addSubview:planView];
}
I want to move the UIImageViews on the screen. I would prefer some sample code.
Where should I put my touch handling code? In the view controller subclass or in the UIView subclass?
I'm trying to base part of my app off of Apple's Image Zooming example, to get zooming, scrolling, and orientation of images that are saved to the app's sandbox.
http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/UIScrollView_pg/Introduction/Introduction.html
I have it sort of working now, except that when the ScrollView loads, it's blank. The code looks something like this:
#interface PhotoViewController : UIViewController <UIScrollViewDelegate> {
UIScrollView *imageScrollView;
UIImageView *imageView;
}
#property (nonatomic, retain) IBOutlet UIScrollView *imageScrollView;
#property (nonatomic, retain) UIImageView *imageView;
#end
#implementation PhotoViewController
#synthesize imageView, imageScrollView;
- (void)viewDidLoad {
[super viewDidLoad];
imageScrollView.bouncesZoom = YES;
imageScrollView.delegate = self;
imageScrollView.clipsToBounds = YES;
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"image1.jpg"]];
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.backgroundColor = [UIColor blackColor];
imageView.userInteractionEnabled = YES;
[imageScrollView addSubview:imageView];
imageScrollView.contentSize = [imageView frame].size;
}
The xib has a Photo View Controller->Scroll View->View structure. I have a feeling this is where the problem is. I tried to hook up all the outlets identically to the example, but under Referencing Outlets the example has a viewController hooked up to the ImageZoomingAppDelegate. Since my PhotoViewController is a subview, there's not a place to hook up the viewController like that.
Here's how I bring up the PhotoViewController:
(IBAction) photoButtonPressed: (id) sender {
viewController = [[PhotoViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
}
I know I must be just "this close" to having it all hooked up right, but I don't understand the relationship of the xib to the code well enough to know how to debug it. I'm not even sure if I know enough to ask the right questions.
Try changing viewController = [[PhotoViewController alloc] init]; to
viewController = [[PhotoViewController alloc] initWithNibName:#"PhotoViewController" bundle:nil];
(of course change the text string to whatever you called your xib file).
i struggled almost 1 hour but i couldn't figure it out as how to display UIactivity indicator in UItableview as i cant use IB in UItableview(its not dragging) on iphone
i used this and its working
but i want to display in viewDidload
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//loadingView =[LoadingView loadingViewInView:[self.view.window.subviews objectAtIndex:0]];//.window.subviews
NSLog(#"dgdddddddddddddddddddd");
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(130, 10, 25, 25)];
//UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 30.0, 320.0, 60.0)];
activityView.center=customView.center;
[activityView startAnimating];
[ customView bringSubviewToFront:activityView];
[customView addSubview:activityView];// [headerLabel release];
return [customView autorelease];
}
kindly suggest
if the view attribute of the file is linked to the UITableView , then the subview will not be added. Try replacing the view attribute with a normal view which contains a table view and try adding the indicator. Also try to make the file owner class from uitableviewcontroller to uiviewcontroller class.
I have a weird problem.
I'm subclassing UIViewController and adding a tableView property in which I load a UITableView.
Now I'm adding this UITableView to the parent's subviews.
Works fine but I get TWO TableViews. One standard styled TableView and one the way I wanted it to be on top of the standard one. Both contain the correct data though.
#interface RootViewController : UIViewController <ABPersonViewControllerDelegate, UITableViewDelegate, UITableViewDataSource> {
UITableView *tableView;
ToolbarController *toolbar;
...
}
#property(nonatomic, retain) UITableView *tableView;
#property(nonatomic, retain) ToolbarController *toolbar;
...
#end
#implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
CGRect mainViewBounds = self.parentViewController.view.bounds;
CGFloat toolbarHeight = 44;
toolbar = [[ToolbarController alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(mainViewBounds), toolbarHeight) parentView:self];
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, toolbarHeight, CGRectGetWidth(mainViewBounds), CGRectGetHeight(mainViewBounds) - toolbarHeight) style:UITableViewStylePlain];
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.rowHeight = 60.0;
[tableView tableView].delegate = self;
[tableView tableView].dataSource = self;
tableView.backgroundColor = [UIColor clearColor];
[self.parentViewController.view addSubview:tableView];
[self.parentViewController.view addSubview:toolbar];
}
#end
------UPDATED------
I just wrongly pasted one part
[tableView tableView].delegate = self;
[tableView tableView].dataSource = self;
is actually in code
tableView.delegate = self;
tableView.dataSource = self;
-------UPDATE 2--------
If I don't create my own UITableView by
tableView = [[UITableView alloc] ...]
then there is one automatically set for me.
This would be fine for me... I don't need to init one, but I can't change the frame on the standard one.
tableView.frame = CGRectMake(0, toolbarHeight, CGRectGetWidth(mainViewBounds), CGRectGetHeight(mainViewBounds) - toolbarHeight);
Setting frame has no effect whatsoever...
i Had the same issue you probably be converting the UITableViewController to UIViewController and Your RootViewController might have the uitableview.
Make the Property of _tableview in your RootviewController with IBOutlet. And link it with the tableview in your XIB .
Don't alloc _tableview in RootviewController and Don't addsubview it .
Instead of this,
[tableView tableView].delegate = self;
[tableView tableView].dataSource = self;
Have you tried just using:
tableView.delegate = self;
tableView.dataSource = self;
I don't know why it would be that, but it's the only thing that's standing out. Also make sure you haven't got another UITableView set up in IB.
It might also have something to do with toolbarController.
I'm assuming it's a custom class, so make sure you're not creating a UITableView in that.
I ran into same issue...
Instead of adding tableview to the view controller directly ([self.parentViewController.view addSubview:tableView];), use following way..
UIView *totalView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[totalView addSubview:tableView];
self.view=totalView;
Hope this fixes it (for #kris too!)