cocoa-touch

convertPoint:toView: in landscape mode giving wrong values

风流意气都作罢 提交于 2020-01-11 17:09:31
问题 I have a view which is created in landscape mode (long after rotation etc.). In this view, I want to find a point relative to the main window. The following code works in portrait mode, but in landscappe it still returns values as if it were in portrait. CGPoint ptRelativeToWindow = [self convertPoint:self.bounds.origin toView:nil]; Solved This solved the problem and gives the right coordinates: [self convertPoint:self.bounds.origin toView:[UIApplication sharedApplication].keyWindow

Adding the little arrow to the right side of a cell in an iPhone TableView Cell

…衆ロ難τιáo~ 提交于 2020-01-11 14:53:42
问题 This should be simple enough. I have an iPhone app with a TableView. How do I add the little classic arrow to the righthand side of each cell? 回答1: Just set the respective accessoryType property of UITableViewCell . cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; In Swift 3 , cell.accessoryType = .disclosureIndicator 回答2: You can do this in Interface Builder. Simply click click on the Table View , go to Prototype Cells on the right side and make it 1. Then click that

Adding the little arrow to the right side of a cell in an iPhone TableView Cell

佐手、 提交于 2020-01-11 14:53:28
问题 This should be simple enough. I have an iPhone app with a TableView. How do I add the little classic arrow to the righthand side of each cell? 回答1: Just set the respective accessoryType property of UITableViewCell . cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; In Swift 3 , cell.accessoryType = .disclosureIndicator 回答2: You can do this in Interface Builder. Simply click click on the Table View , go to Prototype Cells on the right side and make it 1. Then click that

How do I write a custom init for a UIView subclass in Swift?

限于喜欢 提交于 2020-01-11 14:48:53
问题 Say I want to init a UIView subclass with a String and an Int . How would I do this in Swift if I'm just subclassing UIView ? If I just make a custom init() function but the parameters are a String and an Int, it tells me that "super.init() isn't called before returning from initializer". And if I call super.init() I'm told I must use a designated initializer. What should I be using there? The frame version? The coder version? Both? Why? 回答1: The init(frame:) version is the default

how to pass objects between view controllers

て烟熏妆下的殇ゞ 提交于 2020-01-11 14:39:49
问题 I have a table view that lists athletes. when an athlete is selected, I wish to have the detail view controller (the controller that is pushed onto the stack) to know all the attributes about the athlete. his/her name, birthday, phone number, etc. But im unsure on how to pass this information. allathletes.h -(void)viewWillAppear:(BOOL)animated{ AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; _managedObjectContext = [appDelegate managedObjectContext]; NSFetchRequest

Problem copying NSMutableArray

泪湿孤枕 提交于 2020-01-11 13:37:19
问题 I am trying to copy one array to another: NSMutableArray *itemsCopy = [[NSMutableArray alloc] initWithArray:self.items copyItems:YES]; but I get the error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Item copyWithZone:]: unrecognized selector sent to instance 0x5a74900' *** Call stack at first throw: ( 0 CoreFoundation 0x025afc99 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x026fd5de objc_exception_throw + 47 2 CoreFoundation 0x025b17ab -[NSObject

How to change format of date/time?

夙愿已清 提交于 2020-01-11 11:37:38
问题 I have this date and time format: 2010-05-19 07:53:30 and would like to change it to: Wednesday @ 7:53PM 5/19/2010 I'm doing this, which gets the current format: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; but when I change the format, I end up with a null. For example: formatter.dateFormat = @"hh:mm tt MM-dd-yyyy"; date = [formatter stringFromDate:formattedDate]; date will be null. I want to put the end result into an NSString.

Autocomplete UITextField

≯℡__Kan透↙ 提交于 2020-01-11 10:54:09
问题 I want to auto complete a text field from a custom value Having researched Google and SO here UITextField Autocomplete - iPhone SDK I tried this: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([string isEqualToString:@"Fac"]) { _clientField.text = @"Factory"; } return YES; } Problem is I get no predicted value entered Factory , just the typed value Fac EDIT Tried this based on answers... - (BOOL)textField:

How do I make a label load content located on a website?

我的梦境 提交于 2020-01-11 10:38:16
问题 I want to make a label which indicates if a band is on tour (System of a down fyi) So I want a label in the interface to adjust to a value given on my server. ( So it needs to extract data from a (.html) file and display it as a label. ) WebViews are messy in my opinion and a label looks better. 回答1: I'd recommend using AFNetworking - http://afnetworking.com/. It will allow you to pull data from your server. For example, you could create an XML file containing the data that you need. Then you

Writing a NSArray to file

被刻印的时光 ゝ 提交于 2020-01-11 10:16:21
问题 I am trying to save/write an Array to the documents directory, and I am completely stuck. I have checked this code with multiple sources online. I switched from and NSArray to a NSMutableArray and that didn't work. From what I can tell is the file isn't being written, because test is coming back null. Thanks in advance NSArray *results = [parser objectWithData:data1]; NSMutableArray *array2 = [[NSMutableArray alloc] initWithArray:results]; // Create a dictionary from the JSON string NSArray