Uitableview within uiview - xcode

I have Uitable view within uiview with navigation bar , I want to add button to the navigation bar to edit the contents of uitableview
any suggestion how to do that please

I think that you want to place your UITableView controller within a UINavigationController (see the UINavigationController class reference for more information).
In your UIViewController for the UITableView, you need to override the methods found under the "Configuring a Navigation Interface" section of the Apple Developer Documentation.
Within this section of methods lies - (UIBarButtonItem *)editButtonItem, which you could override to provide the button for your editing purpose. Under the hood, the UINavigationController will call this method to get the edit button for its user interface. Using this technique ensures that your app stays consistant with the user expierence iOS users have come to love.

There is solution that I tried and worked for me. The solution is
in .h file
UIBarButtonItem *edit;
and set property line as
#property (nonatomic , retain) IBOutlet UIbarButtonItem *edit;
in .m file
in your action handler of the button add
[self.tableView setEditing:TRUE];
Open the .xib file of your view controller and add a UIBarButtonItem either to left or right side of the Navigation Bar and connect the respective IBOutlet to edit button and also the selector method.
Now in the delgate of tableView add the following method
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//sets the editing style for every row.
return UITableViewCellEditingStyleDelete;
}
Now you can play around with the UITableViewDelegate Methods and also the above methos to get the desired functionality.
Hope it works and do communicate if it does!!

Related

How to link ibOutlet from subview to custom UIView Class in storyboard xcode

I think this image explains it all. I have a subclass of UIView that I've entered into the class field. I'm trying to connect ibOutlets between the storyboard and class implementation. It's not giving me an error, but it's not working either. Is this another xcode bug, or am I expecting this to work in a way that it won't?
Here is a solution:
1) Type an IBOutlet by hands in your header file, example:
#property (strong, nonatomic) IBOutlet ProgressBarElementView *targetProgressElement;
2) Drag the pin from the code to the element in document outline zone
I have the same problem.. I saw that if you add the custom class to the root view in the view controller, it will work.. In your case this is the initial View, listed under Bottom Layout Guide
But there must be a better way
To overcome XCode stubborness, especially when you need to hook up different enums from UIControlEvent than UIControlEventTouchUpInside, I'd rather use code directly from within the custom view class:
SWIFT
button.addTarget(self, action:#selector(ClassName.handleRegister(sender:)),
for: .touchDragExit)
OBJECTIVE-C
[self.button addTarget:self
action: #selector(buttonTouchDragExitAction:)
forControlEvents:UIControlEventTouchDragExit];
One might include such code in awakeFromNib or viewDidLoad or where it best suits.
write the outlet inside your custom UIView
#IBOutlet weak var imageView: UIImageView!
then drag it into the storyboard on the view

Can't CTRL+Drag NSButton to custom NSView header

I'd like to create a custom NSTableCellView instantiated by Interface Builder. I've set my Table Cell View class to MyTableCellView, and properly created MyTableCellView : NSTableCellView .m/.h files.
However, I just can't CTRL+Drag a simple button from inside this view to MyTableCellView.h in order to create an IBOutlet.
Here is a video to show what happens: http://youtu.be/sNNbuVT-SZs.
How the view is subclassed:
How I try to CTRL+Drag a button
Also, sometimes, Interface Builder just don't allow the cell view's class to be modified. What's happening ?
I finally found a solution, that is a little weird but works as expected. Instead of connecting the NSButton to MyTableCellView header directly, I used the reversed path:
Manually create an outlet:
#property(retain, nonatomic) IBOutlet NSButton* button;
Then click the empty circle on the left, and drag it to your XIB file's button:
I have no idea why it works this way, please let me know if you know the anwser.

XCode Storyboard: how to create a segue when the segue trigger is not on storyboard

So I started playing with storyboards in XCode 4.3.2. I started with the Master-Detail application (split view application for iPad). In the detail view (named DetailVC) I have a view where I displayed an array of custom views.
The custom views (named GridView) have a tap gesture recognizer which is supposed to handle the tap event on each custom view. Tapping a GridView pushes a view controller show some search results (named SearchResultsVC).
With GridView created in a separate nib file, and the DetailVC and SearchResultsVC reside in storyboard, how can I create a push segue with destination SearchResultsVC? I just created a segue between DetailVC and SearchResultsVC? Is there someway I can trigger this segue programatically from inside the GridView class when tap gesture is recognized????
In the method where you handle the tap use:
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
In your StoryBoard control drag from your DetailVC to your SearchResultVC and choose what type of segue you would like. Make sure to name your segue identifier the same as the one in the method above in attributes inspector.
I'm gonna try and improve my answer I messed it up I think:
1) In your DetailVC.h create an instance variable for your GridView like this
IBOutlet UIView * gridView;
also create a getter method and an IBAction for your grid view like this
-(UIView *)gridView;
-(IBAction)myGridGotPressed:(id)sender;
2)Now in your DetailVC.m implement your methods like this
-(UIView *)gridView{
if(!gridView){
[[NSBundle mainBundle] loadNibNamed:#"GridView" owner:self options:nil];
}
return gridView;
}
Also implement your IBAction like this
-(IBAction)myGridGotPressed:(id)sender{
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
}
3) To make this work you need to change the filesOwner class of your GridView to DetailVC and then hook up the outlets and Actions as normal.
I hope that helps.

Why is my UIView not the "parent" of my UIImageView?

I have an mainUIView within which there is a customised UIImageView (named myImageView).
In the myImageView.h file, I have declared:
#property (strong, nonatomic) mainViewController *viewController;
and in the myImageView.m file, I have the following codes:
self.viewController = self.parent;
This lines raises an error indication:
Property 'parent' not found on object of type myImageView.
I thought putting the myImageView inside the mainUIView would make the default parent-and-sub relationship, but obviously it's not so.
In the main storyboard, I tried to Ctrl-drag the myImageView to the mainViewController, but no options pops up for me to select delegate.
Can anyone give me explanation of these please? I'm feeling a bit confused... Many thanks!
As your myImageView is a UIView is has no parent. Is just has a superview which again is a UIView. Basically a view doesn't know its controller. Although the controller can implement a view's delegate to get informed about events. So your AppDelegate knows your ViewController and the controller knows your ImageView. The AppDelegates window knows the view of your controller which will most likely contain the whole view hierarchy (except AlertViews, HUDViews, modal views and simmilar...).
I think what you want to do works best implementing the delegate pattern. (see Apple Docs)

Hide/Unhide UINavigationbar when the screen is tapped

I'm very new with iOS Development and I have just created one of my first apps, in my .xib file I have a UINavigationBar that I want to hide/show when a part of the screen is tapped by the user (like in the Photo app). I've found some snippets online but I don't know where and how to use those.
I'd appreciate a lot if somebody could give me detailed informations about how to do this.
Add this toggle method anywhere in your UIViewController. This hides on first tap and shows again in second tap.
- (void)toggleNavBar:(UITapGestureRecognizer *)gesture {
BOOL barsHidden = self.navigationController.navigationBar.hidden;
[self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
}
If there is no navigation controller, link the navigation bar with an IBOutlet and replace with
- (void)toggleNavBar:(UITapGestureRecognizer *)gesture {
BOOL barsHidden = self.navBar.hidden;
self.navBar.hidden = !barsHidden;
}
Then add the following in the method -(void)viewDidLoad {}
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(toggleNavBar:)];
[self.view addGestureRecognizer:gesture];
[gesture release];
If the view where you are going to tap is a UIWebViewController, you have to add the protocol to the view controller and set it as delegate gesture.delegate = self; then add the following:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
This is needed because the UIWebViewController already implements its own gesture recognizers.
Ultimately, you want to send the -setHidden: message to your navigation bar. The easiest way to do this is to make an Outlet and an Action in your in your view controller. Then, in your .xib file, connect the navigation bar to the outlet and some button (even a large, full screen one) to the action.
Outlets and Actions are basic techniques used over and over in iOS
(and Mac) programming, so if you don't understand them, best go read
up on them now. Every beginning iOS/Mac programming book covers this
topic as does Apple's own Getting Started guide (pay particular
attention to the Configuring the View section).
Inside your action, send a message to the outlet like so:
-(void)myButtonAction:(id)sender{
[[self myNavigationBarOutlet] setHidden:YES];
}
This will hide the navigation bar whenever your button is tapped.
(This assumes you have a UINavigationBar in your .xib like you say. These directions will be different if you're working with a UINavigationController that manages its own UINavigationBar)

Resources