IPhone DevelopmentThe problem is what we will introduce in this article, mainly about words.Iphone DevelopmentSome bugs encountered in the process, how to solve them, let's take a look at the detailed content of the one-to-one solution.
Q: [Let tableview scroll to the top] when entering a tableview from another view, it will always automatically scroll to the previous scroll bar position. I want it to enter this tableview every time, which message should I use to roll back to the top?
A: Method 1: Use scrollToRowAtIndexPath
Method 2:
- - (void)scrollToTop {
- [self.tableView setContentOffset:CGPointMake(0,0) animated:YES];
- }
- - (void)scrollToBottom {
- NSUInteger sectionCount = [self.tableView numberOfSections];
- if (sectionCount) {
- NSUInteger rowCount = [self.tableView numberOfRowsInSection:0];
- if (rowCount) {
- NSUInteger ii[2] = {0, rowCount - 1};
- NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:ii length:2];
- [self.tableView scrollToRowAtIndexPath:indexPath
- atScrollPosition:UITableViewScrollPositionBottom animated:YES];
- }
- }
- }
Method 3:
- [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:_currentRow inSection:0] animated:YES
- scrollPosition:UITableViewScrollPositionMiddle];
First use selectRowAtIndexes: select the number of rows. If you scroll to the superview of tableview, scrollview is scrollview. If scrollview can scroll to a position, the position = table row height * index is calculated, the scroll position is displayed.
Q: When Using SLQite3 to call the sqlite3_bind_text function, the char * type parameter must be used. In the sqlite3_column_text function, the char * type return value must be used, how to convert a String object between NSString and Char?
A:
Convert NSString to char *: [NSString UTF8String]
Convert char * To NSString: [NSString stringwithuf8string:]
For example:
- //=======NSString to char *==============
- NSString *updateSign = @"AAAA";
- sqlite3_bind_text(statement, 1, [updateSign UTF8String], -1, NULL);
-
- //=========char * to NSString============
- columnName.text = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
Q: How can I solve the problem of "unrecognized selector sent to instance" in iPhone application development?
A: Most of the reasons for this problem are that the object is release in advance. If you don't want it to be release, the pointer is still there and the object is no longer there. The main reason is that no self is used for attributes in the init initialization function. [attribute] = xxxx is used to assign values, but directly assign values to the private variables corresponding to the attribute. As a result, the attribute object is released in advance without retain. Solution: Use the self. [attribute] = xxxx statement to assign values to the attribute.
Q: What should I do if I want to calculate the data difference between two NSDate data for several days, several hours, and several seconds?
A:
- NSTimeInterval
- time = [date1 timeIntervalSinceDate:date2];
Time is the second interval between date1 and date2. If it is greater than zero, date1 is later than date2, and vice versa .... It takes several minutes or seconds to get the result.
Q: How can I implement a logon page and jump to another page after successful logon? I want to implement a logon page and click a logon button to jump to the UITabBarController interface. How can I deal with this )?
A: try the following method:
1. Put LoginViewController and UITabBarController in MainWindow. xib.
2. Add the following code to the application in Delegate.
- [window addSubview:tabBarController];
- [window addSubview:loginViewController];
3. After Login is successful, add the following code to LoginViewController.
- [self.view removeFromSuperview];
Q: How does one implement timing operations similar to Timer in the iPhone?
A: similar to the following code:
- Timer = [NSTimer scheduledTimerWithTimeInterval :( 3) target: self selector: @ selector (onTimer :) userInfo: nil repeats: YES];
- -(Void) onTimer :( NSTimer *) timer {
- // Process
- ......
- }
Q: A UITextField in UITableViewCell displays a soft keyboard when you click UITextField. To return the UITextField value, I bound the rootViewController-(IBAction) textAction: (id) sender to the valueChanged event; however, I also need to know the indexPath of the Cell. what should I do with row?
A: There are two methods:
Method 1
Obtain the Cell where UITextField is located.
- NSIndexPath *path = [tableView indexPathForCell:
- (UITableViewCell *) [ (UITextField *)sender superview] ];
Method 2
First, set the cell. tag and textField. tag values when table loadview creates a cell.
- tmpcell.tag = 3;
- tmpcell.textField.tag = 3;
Then, when the event is started
- - (IBAction)textAction:(id)sender
- {
- NSInteger tag = [sender tag];
- NSIndexPath *indexPath = [self.tableView indexPathForCell: (UITableViewCell *)[self.tableView viewWithTag:tag]];
- [[[rawElementsArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] setValue:[sender text] forKey:@"value"];
- }
Summary:IPhone DevelopmentThe problem summary is complete. I hope this article will help you!