Helo. I have big problem.
So i have .xib with view (my popover) , tableview and button.
In popover.m i have just static method to load .xib and close button delegate. Popover is not VC
I have to customize my table and load data from DB.I created
TableView.m but i cant drag and drop TableView like outlet.
In addition, I implemented delegate/datasource
Have someone similar problem ? :)
I will be grateful for all the advice
Code from popover.
+ (TaggingAdditionl *) createInstance {
TaggingAdditionl *taggingXibView = [[[NSBundle mainBundle] loadNibNamed:#"TaggingPopOver" owner:self options:nil] objectAtIndex:0];
[taggingXibView setFrame:[UIScreen mainScreen].bounds];
[taggingXibView setBackgroundColor:[UIColor redColor]];
return taggingXibView;
}
- (IBAction)didPressCloseButton {
[self.delegate taggingAdditionDidClose: self];
}
#end
Related
I've got a CollectionView which was programmatically created, now I want to switch to another CollectionView by selecting one of its Cells. Heres my code so far, but nothing happens:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
NSLog(#"Cell selected");
DetailCell *detailCell = [[DetailCell alloc] init];
[self.navigationController pushViewController:detailCell animated:YES];
}
Console says "Cell selected", so the CollectionView recognizes my touch, but the app won't switch to the other view. I've created a ViewController with the custom Class "DetailCell".
I'd check and make sure your self.navigationController isn't nil.
I just solved this problem :
mainView .m
cView = [[CollectionView alloc]init];
cView.view.frame = CGRectMake(0, 0, 320, 436);
cView.nav = self.navigationController;
[_contentScrollView addSubview:cView.view];
CollectionView.h
#property (nonatomic,weak) UINavigationController *nav;
CollectionView.m
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{
DetailCell *detailCell = [[DetailCell alloc] initWithDetails:_pageCategorie and: indexPath];
[_nav pushViewController:detailCell animated:YES];
}
I have a UIViewController (Main VC) into which another UIView is loaded as subview when a button is tapped on MainViewController. Actually I load a map view as subview in the main view controller. For that purpose I need to pass the coordinate from MainViewController to the subview (map view) to create the annotation there & then loaded inside the MainViewController.
In MainViewController the following method loads the subview correctly:
-(IBAction)showUserLocation{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"UserCurrentLocationView" owner:self options:nil];
UIView *currentLocationView = [nib objectAtIndex:0];
currentLocationView.frame = CGRectMake(8, 10, currentLocationView.frame.size.width, currentLocationView.frame.size.height);
[thirdPortion addSubview:currentLocationView]; // thirdPortion is a View Outlet in the Main VC wh
}
Here I want to pass a coordinate (lat/lon) to the UserCurrentLocationView 's class so that it can prepare the map and I can see the pointed map in the MainViewController when showUserLocation method is called by a button.
What is the way to set the value of a property that stays on the UIView (Subview) from the MainViewController.
Thanks in advance!
You have to subclass the UIView (I will call it YourView) and add a two properties for long and lat. Then put it as the class for your .xib - file named UserCurrentLocationView.
Then you do the following to set the variables.
-(IBAction)showUserLocation{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"UserCurrentLocationView" owner:self options:nil];
YourView *currentLocationView = (YourView *)[nib objectAtIndex:0];
currentLocationView.lon = self.fooValue;
currentLocationView.lat = self.fooValue2;
currentLocationView.frame = CGRectMake(8, 10, currentLocationView.frame.size.width, currentLocationView.frame.size.height);
[thirdPortion addSubview:currentLocationView]; // thirdPortion is a View Outlet in the Main VC wh
}
I need to create several similar views
In a easy way,I create some views in xib(each full screen)
And I have a view controller to use this xib's views,code like this:
NSArray* views = [[NSBundle mainBundle] loadNibNamed:#"MyXibName" owner:nil options:nil];
[self.view addSubview:[views objectAtIndex:aIndex]];
At this moment,view shows alright.
Now,there's some buttons in those views,so I connect a outlet for each view
bad thing happened
app crashed due to
uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x969db50> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
Analyse:
Although my xib file's "File Owner" has been set,but there's no connection between xib and the only view controller.
How could I get the pointer of a view's button?
You can do it like this:
NSNib* aNib = [[NSNib alloc] initWithNibNamed:#"MyGreatNib" bundle:nil];
NSArray* topLevelObjs = nil;
for (SomeClass *obj in myOwnerObjects) {
topLevelObjs = nil;
if (![aNib instantiateNibWithOwner:obj topLevelObjects:&topLevelObjs])
{
NSLog(#"Warning! Could not load nib file.\n");
return;
}
for (id topLevelObj in topLevelObjs) {
if ([topLevelObj isKindOfClass:[NSView class]]) {
NSView *otView = (NSView *)topLevelObj;
// set frame...
[self addSubview:otView];
}
}
}
Oops...
I just found something.
UINib* xib = [UINib nibWithNibName:#"MyXibName" bundle:nil];
UIView* view = [[xib instantiateWithOwner:self options:nil] lastObject];
It works!
You can design xib as per your need by defining class UIView
Code in .m file:
NSArray* objects = [[NSBundle mainBundle] loadNibNamed:#"Interface" owner:nil options:nil];
UIView* mainView = [objects objectAtIndex:0];
for (UIView* view in [mainView subviews]) {
if([view isKindOfClass:[UILabel class]])
{
UILabel* label = (UILabel*)view;
//....As You Wish...
}
}
Default implementation of -loadView creates the view or loads NIB. As far as I know, there is no way to know the final size of the view at time of creation in -loadView. So the default view size is set to [[UIScreen mainScreen] bounds]. This is because it may be difficult to work work with zero frame view in -viewDidLoad and other methods.
Your one-line implementation may look like this:
- (void)loadView {
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
}
You don't need to set the autoresizing mask, because you don't know in what context the view will be displayed. The caller is responsible to set you correct frame, autoresizing mask and similar external attributes (I call them like this).
Imagine this in a UINavigationController method:
// we are pushing new VC, view is accessed for the first time
pushedVC.view.frame = CGRectMake(...);
It is setting the correct frame, but your -loadView is called just before that -setFrame:. So during -viewDidLoad you have temporary non-zero frame, just to be able to setup subviews and internal autoresizing. After this, the correct frame is set to you and in -viewWillAppear: you have final frame.
When I load my xib: AboutViewController as a subview of the view contentView, I just get a blank black screen, can someone help??
UIView* moreView = [[[NSBundle mainBundle] loadNibNamed:#"AboutViewController" owner:self options:nil] lastObject];
[_revealView.contentView addSubview:moreView];
You should use view controllers instead, then just access the view of the view controller:
UIViewController * aboutVC = [[UIViewController alloc] initWithNibName:#"AboutViewController" bundle:nil];
[_revealView.contentView addSubview:aboutVC.view];
Alternatively, you may be interested in presenting the view modally:
[_revealView.contentView.viewController presentModalViewController:aboutVC
animated:(BOOL)animated];
If you are not using ARC, you will have to manage aboutVC manually with retain and release.
How would I make this code animate in the SplashView NIB instead of just making it appear (e.g. the UIModalTransitionStyleFlipHorizontal style)? I am using a UITabBarController type project.
- (IBAction)showSplash:(id)sender {
// Hide toolbar
self.tabBarController.tabBar.hidden = YES;
// Splash
[[NSBundle mainBundle] loadNibNamed: #"SplashView" owner: self options: nil];
[self.view addSubview: splashView];
[window makeKeyAndVisible];
}
Bit hard to tell your context with this small bit of code. Basically, if you want to push a viewController modally, in your -(IBAction)showSplash method (you don't need to send the sender if you're not using it, BTW), I would use some code similar to this:
SplashViewController *svc = [[SplashViewController alloc] init]; (assuming nib is same name)
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:svc animated:YES];
[svc release];
Then in your SplashViewController you would have an IBAction that calls:
[self dismissModalViewController animated:YES];
You don't actually have to hide the tabBar when you are presenting a modalViewController. It won't be there. The idea of a modalViewController is that it blocks all user interaction with the app except for the modal view, until it is dealt with.
Hope this helps.