IPhone development question Summary

Source: Internet
Author: User
Tags date1

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:

 
 
  1. - (void)scrollToTop {  
  2.         [self.tableView setContentOffset:CGPointMake(0,0) animated:YES];                  
  3. }  
  4. - (void)scrollToBottom {  
  5.         NSUInteger sectionCount = [self.tableView numberOfSections];  
  6.         if (sectionCount) {  
  7.                 NSUInteger rowCount = [self.tableView numberOfRowsInSection:0];  
  8.                 if (rowCount) {  
  9.                         NSUInteger ii[2] = {0, rowCount - 1};  
  10.                         NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:ii length:2];  
  11.                         [self.tableView scrollToRowAtIndexPath:indexPath   
  12.                          atScrollPosition:UITableViewScrollPositionBottom animated:YES];  
  13.                 }  
  14.         }          

Method 3:

 
 
  1. [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:_currentRow inSection:0] animated:YES   
  2.  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:

 
 
  1. //=======NSString to char *==============  
  2.  NSString *updateSign = @"AAAA";  
  3.  sqlite3_bind_text(statement, 1, [updateSign UTF8String], -1, NULL);  
  4.    
  5. //=========char * to NSString============  
  6.  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:

 
 
  1. NSTimeInterval      
  2. 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.

 
 
  1. [window addSubview:tabBarController];  
  2.  [window addSubview:loginViewController]; 

3. After Login is successful, add the following code to LoginViewController.

 
 
  1. [self.view removeFromSuperview]; 

Q: How does one implement timing operations similar to Timer in the iPhone?

A: similar to the following code:

 
 
  1. Timer = [NSTimer scheduledTimerWithTimeInterval :( 3) target: self selector: @ selector (onTimer :) userInfo: nil repeats: YES];
  2. -(Void) onTimer :( NSTimer *) timer {
  3. // Process
  4. ......
  5. }

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.

 
 
  1. NSIndexPath *path =    [tableView indexPathForCell:      
  2. (UITableViewCell *) [ (UITextField *)sender superview] ]; 

Method 2

First, set the cell. tag and textField. tag values when table loadview creates a cell.

 
 
  1. tmpcell.tag = 3;  
  2. tmpcell.textField.tag = 3; 

Then, when the event is started

 
 
  1. - (IBAction)textAction:(id)sender  
  2.  {  
  3.          NSInteger tag = [sender tag];  
  4.          NSIndexPath *indexPath = [self.tableView indexPathForCell: (UITableViewCell *)[self.tableView viewWithTag:tag]];  
  5.          [[[rawElementsArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] setValue:[sender text] forKey:@"value"];  
  6.  } 

Summary:IPhone DevelopmentThe problem summary is complete. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.