Apple watch interface - ios

I am designing apple watch application where i need to show top10 feed title and i have successfully shown it. in next step i have to add action event to tap which will redirect user to next screen but i am confused which controller to use here. i have to show all feeds in pagination format and then on click i have to show its detail view.
does anyone tried with this approach? i am using UIButton over there but its having text limitation so cant use it and for tableview it scroll verticaly where as i need horizantle scroll.

alph0x's answer is pretty useful. But you can also do another thing to perform what you are asking in case you only want that the action will do when push in a specific button of the row.
This second solution consists on create a class for the custom row with an IBAction
#import <WatchKit/WatchKit.h>
#interface MyRow : NSObject
// Methods
- (IBAction)buttonClick;
#end
And in the buttonClick method, you can specify the action as in the follow example using pushControllerWithName:context to go to a specific interface controller
#import "MyRow.h"
#implementation MyRow
- (IBAction)buttonClick {
[self goToInterface:#"feedInterface"];
}
- (void)goToInterface:(NSString *)interfaceName{
NSDictionary *contextToSend = [NSDictionary dictionaryWithObjectsAndKeys:#"FeedTitle", #"title",
#"lalala", #"secondValue",
#"lelele", #"thirdValue",
#"other value", #"other", nil];
[self pushControllerWithName:interfaceName context:contextToSend];
}
#end
You can send your row info through context. In that example I have decided to send a dictionary with some values.
In the interfaceName param you have to specify the Interface Controller Identifier that you can set in your storyboard. See the image below:
And tell to the XCode that your table row has the custom class MyRow
Note: don't forget to assign your button to the IBAction method ;)

If I understand, you need to have a table with 10 rows, and you need to be able to tap in one row, and view the details about the one you selected, if thats correct, you only need to use the Method from WKInterfaceTable "- (id)rowControllerAtIndex:(NSInteger)index", with this one (works like UITableView one with the delegate) you can handle every row action after being tapped.

Related

How to make a call with button in iOS

This is my first attempt at creating an app. and using Xcode.
The reason this question hasn't been answered before is because there are no answers to my question from the perspective I'm currently at, namely, I've followed the instructions on this URL to creating an app:
http://www.wikihow.com/Make-an-iPhone-App
I have got to the Part 3 of 5: Creating the App, section 6 - thereafter my question is not answered - which is how to make my button make a call when tapped.
Therefore I am now, in Xcode at the point where (remember I followed those instructions on the linked page) I have my one button on the screen but ALL the instructions I could find doesn't address exactly what I need to do to make that button make a call.
Some examples show code like here: Making a Button Call a Phone Number in iOS
but doesn't tell me what to do with that code, I'm new to all of this so finding out the exact steps from this point has been brutal at best. Also, all the code I have tried pasting into sheets that have code in them (by clicking around) the code shows errors - all the code I've obtained from the web.
Any help?
P.S. On this page, a poster says that there is actually a button that is associated with making calls, but I again, know not where to find this…
http://www.insanelymac.com/forum/topic/126918-initiating-a-call-on-iphone/
Open your xib/storyboard side-by-side with your view controller implementation, hold Control and drag your button (interface builder) to your implementation. Xcode should generate an IBAction for you automatically.
On your code, call:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:911"]];
Basically you need to add the code you found into a 'method' in your appdelegate.m file. This 'method' is a segment of code that is executed whenever it is told to.
So in appdelegate.m, add in the lines above #end
- (IBAction)makeCall:(id)sender {
}
Now paste the line of code you found in between the two curly brackets. Now whenever 'makeCall' is called that line of code you found will be executed which will make a phone call (hopefully)
The next step is making the button tell the 'makeCall' method to run. In order to do this you need to 'declare' the makeCall method, it's the equivalent of putting an item up on sale on eBay: in the previous step you made the item(method), now you want to show the world it's available.
Appdelegate.h is the equivalent to eBay/Craigslist/gumtree in this scenario: add this line of code anywhere above #end:
-(IBAction)makeCall:(id)sender;
Now the final step is to link your button to this, and it's the easiest part. Go back to your interface builder and click on your button. Right click the button and drag a line to the blue box on the left called 'AppDelegate' (this is the files you added code to earlier, remember?) and select makeCall from the little list that pops up. You have successfully linked your button to your method, so now when you click the button you should be able to make a call!
If you want to know more about the specifics of the code you just added, IBAction is the type of method, and it means a method that can have buttons linked to it in interface builder. The (id)sender part means that whenever the method is called, the object/button that called the method is passed along so the method can see who 'sent' for it.
Edit: Ok since you're using storyboards we'll need to create what's called a 'view controller'. This basically delegates and controls (hence the name) whatever is on your phone's screen.
So create a new class by going to file -> new -> cocoa class, and in the fields call it ViewController and make it a subclass of UIViewController.
Now we'll need to copy all the code that we added to appdelegate.h and appdelegate.m over to viewcontroller.h and viewcontroller.m, with the code we added to the appdelegate.h being copied to the same place in viewcontroller.h etc.
They should look something like this:
ViewController.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
-(IBAction)makeCall:(id)sender;
#end
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)makeCall:(id)sender {
}
#end
With makeCall having the line of code that you pasted in it earlier.
Now go back to interface builder and click on the little yellow square inside a cube above your screen, and then click on the newspaper-looking icon on the right hand side:
In the class field type in ViewController (it should automatically complete it for you) and then go to the arrow icon tab (which is known as bindings):
Click and drag the little circle beside make call onto your button, and select one of the 'touch down' options that appear. These just mean when to call that method i.e as soon as the user presses the button or when they lift their finger off it. They should now be linked. Give it a try and let me know how it works.

How to Get the value(label) from the TextField inside the custom cell of a table View to post on te URL

I want my iOS app to pass to a URL the text the user types. The relevant code is pasted below. WHen I run the app, the text does not get assigned any value. It stays as null.
I am new to iOS programming and am probably missing something obvious here. Any help/pointers will be appreciated.
Mac OS version : 10.6.8 (64 bit)
Xcode version : 3.2.3
In the snapshop.. "I have created a Table View and placed custom cell inside each row of a table. TextField is inside the custom cell view. Post is a button next to the textField which is a done Button. If I click that button, the text we are entering in the textField should post on URL which i have specified in my code snippet."
NOTE: The text is like a comment and posting this comment that should post on particular image in that cell.
I have copied the code snippet below. I have also attached an image to explain.
-(IBAction)postAction:(id)sender
{
int index=[sender tag];
homecell *cell = [[homecell alloc] init];
UITextField *txt_c =(UITextField *)[cell.txt_comment viewWithTag:index];
NSLog(#"jj %#",txt_c);
gen_data *ut1=[[gen_data alloc]init];
gen_data *ut=[gen_data getInstance];
}
I assume that you have created that view using the interface builder, probably all you need is to connect that textfield as an IBOutlet and access the value.
IBOutlet is the key word here, search for it and you will find really fast the way to do it.
Check this link.
You should get some basics of iOS programming first.
Why are you creating a totally new custom cell that is irrelevant to your UITableView? When you create it that way, it's a totally new UITableViewCell.
You should connect it to it first, get its NSIndexPath and then operate with it and do what you want.
BTW, if you want to see the text of UITextfield you should NSLog myTextField.text
And you could easily write viewWithTag:sender.tag, no need to create an extra ivar here

How to handle concurrency by queue/NSThread for UI design, iOS dev

What I am trying to achieve is simple, from first thinking though. I found it hard to handle at last.
I would like to push a table view as a selection list, user select one cell and the cell string was sent to the previous view as selected string, simple huh??
See two pictures first
what bothers me is that:
I would like to provide (at least) two buttons, one on the left is back button auto-generated by navigation controller, and the right one is for editing. And the navigation controller is defaulted to have two buttons (from my knowledge). So there is no place for "Done" button, which is supposed for user to tap and then confirm and pop to the previous view.
So, when the user tap a cell, "Wearing" for example, I would like the following to happen, automatically and visually SEEable for user:
user can SEE that "Housing" cell is unmarked
then user can SEE that "Wearing" cell is marked
then after a little time gap (say 0.2 second), pop to the previous view and update the selection, automatically.
At first I thought it's easy but it's definitely not. Here is my code for doing it, but working wired
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
dispatch_queue_t queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0ul);
dispatch_async(queue, ^{
//unmark previous cell
if (selectedIndexPath!=nil) {
[[self.tableView cellForRowAtIndexPath:selectedIndexPath]setAccessoryType:UITableViewCellAccessoryNone];
}
selectedIndexPath=indexPath;
//get the selected cell to mark
UITableViewCell *cell=[self.tableView cellForRowAtIndexPath:indexPath];
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
dispatch_sync(dispatch_get_main_queue(), ^{
//wait a little
[NSThread sleepForTimeInterval:0.2];
//return to previous view
NSLog(#"here.........");
if ([objectToUpdateCategory respondsToSelector:#selector(updateCategoryTo:withSelectedIndexPath:)]) {
NSLog(#"sending.......... update info");
[objectToUpdateCategory updateCategoryTo:cell.textLabel.text withSelectedIndexPath:selectedIndexPath];
NSLog(#"sent update info");
}
[self.navigationController popViewControllerAnimated:YES];
});
});
The tricky thing is that if I put [self.navigationController popViewControllerAnimated:YES]; to the last, the view will not visually update the unmark and mark step and go back to the previous view immediately. At first, when I didn't consider the unmark thing, the “queue" stuff in code can do the mark step visually before popping back, but sometimes not working. I don't know if my code is correct, actually I don't quite understand this queue tech from apple. But I'm pretty sure it has something to do with NSThread / queue or else that handle concurrency. I've checking Apple documents for a whole day and found no direct answer.
Hope someone could help me on this, thanks in advance :)
To "after a little time gap (say 0.2 second), pop to the previous view", use the performSelector:withObject:afterDelay: methods or one of its variants, e.g.:
[self performSelector:#selector(delayedPop) withObject:nil afterDelay:0.2];
and put the popViewControllerAnimated in the delayedPop method, e.g.:
-(void)delayedPop{
[self.navigationController popViewControllerAnimated:YES];
}
First of all, as I wrote in my comment, you shouldn't update the UI on a background thread. This will cause a lot of problems, including the UI not being updated immediately. In your case you don't need to use dispatch_async or dispatch_sync at all. What I would do is create a property in the view controller that displays the categories table view:
#property (nonatomic, weak) id<CategoryControllerDelegate> delegate;
When you push the category controller on the stack you set your expense controller as the delegate. Then, when the user makes a selection in the category controller, you call a method on the delegate (defined in a protocol), for example the one in your code sample:
#protocol CategoryControllerDelegate<NSObject>
#optional
- (void) updateCategoryTo: (NSString*) category withSelectedIndexPath: (NSIndexPath*) path;
#end
After that you pop the current view controller off the stack.

Popup creation in IOS/iPad

I have created a popup and in that there is a list of content are displaying in a table view. Now when I click into any row of the tableview, it should call a method, which is available in the parent view not in the popup view. If I use any button in that popup then after selecting a row if I click into that button then it works. The button action is mention in parent view in this way.
[controller.gotoButton addTarget:self action:#selector(clickMe:) forControlEvents:UIControlEventTouchUpInside];
So how to call a method when clicking into a table rows?
Here you can find a pretty good description of delegates.
What you would like to do, can be solved with a protocol/delegate. You should create the protocol in the Popup view's header file, and the implementation in the *.m class. Your parent view should implement the protocol, and don't forget the connection line, the myPopupObject.delegate = self; + the implementation of the protocol's method.
I suggest to use the
if ([delegate respondsToSelector:#selector(myMethod:)]) {
//call the selector
}
verification in the Popup view class, because if the protocol's method is optional, and you hadn't implemented it in the parent class, your app will crash (you won't receive any error/warning message from the compiler, because it was an optional method).
in rowDidSelect,
create a object for the parentview
eg:
parentClass *pc=[parentClass alloc]init];
[pc method:];

How to show the text of an UITextField in an UILabel?

I am building an interface, where I can add events like in a calendar.
In the AddAEventViewController I have Buttons to set the starttime, duration and recurrence.
Every time you press a button a viewcontroller comes up with a UIDatePicker, where you can set your time. The picked component is than displayed in a UITextField. Now when I press the Done-Button, it dismisses the ModalViewController and I am back to my AddAEventViewController. Next to the Durationbutton e.g. is a UILabel, where I want to show now the just picked and in the textfield shown duration.
How do I get access to the AddEventViewController out of an other ViewController? I tried to alloc and init a new one there, but it didnt work!
- (IBAction)pressedDoneButton:(id)sender {
_mainAddWishViewController.labelDuration.text=textFieldDuration.text;
[self dismissModalViewControllerAnimated:YES];
}
Can someone help me please!
Thank you Jules
There are several ways you can do this, all of them documented here. Reading and understanding them will help you a lot in iOS software development.
There are many ways to achieve this. Here is one that is fairly straightforward.
In the "child" viewController, add a delegate property and set it to the parent view controller.
Then in your Done button handler, do something like:
[self.delegate performSelector:#selector(didComplete) withObject:self]
In the parent view controller, define a method as follows:
- (void) didComplete: (YourSubViewControllerClass *) sender
{
self.labelDuration.text = sender.textFieldDuration.text
}
Basically, this implements an informal protocol whereby the subViewController informs the main view controller that it is finished and input values are available.
Note that if you cancel out of the subViewController, don't send the didComplete message.

Resources