首先使用selectRowAtIndexes: 選擇行數,滾動的話tableview的superview時scrollview,scrollview能夠滾動到某個position 那麼就要計算這個position position = table row height * index,就獲得滾動的位置了。
Q:在使用SLQite3調用sqlite3_bind_text函數時須要使用char *類型的參數,在sqlite3_column_text函數中須要使用char *類型的返回值,如何將字符串對象在NSString和Char *之間進行轉換?
A:
將NSString轉換成char *:[NSString UTF8String]
將char *轉換成NSString:[NSString stringWithUTF8String:]
例如:
//=======NSString to char *==============
![](http://static.javashuo.com/static/loading.gif)
NSString *updateSign =
@"AAAA";
![](http://static.javashuo.com/static/loading.gif)
sqlite3_bind_text(statement, 1, [updateSign UTF8String], -1, NULL);
//=========char * to NSString============
![](http://static.javashuo.com/static/loading.gif)
columnName.text = [NSString stringWithUTF8String:(
char *)sqlite3_column_text(statement, 1)];
Q:如何解決在iPhone程序開發中常遇到「unrecognized selector sent to instance」的問題?
A:形成該問題的大部分緣由是
對象被提早release了,在不但願它release的狀況下,指針還在,對象已經不在了。主要是由於init初始化
函數中,
沒有對屬性使用self.[屬性]=xxxx的方式賦值,而是直接對屬性所對應的私有變量進行賦值,致使屬性對象沒有retain而提早釋放。解決方法,使用self.[屬性]=xxxx語句對屬性賦值便可。
Q:我想計算兩個NSDate的數據相差幾天幾個小時幾分幾秒怎麼辦阿?
A:
![](http://static.javashuo.com/static/loading.gif)
NSTimeInterval time = [date1 timeIntervalSinceDate:date2];
time是date1和date2的秒間隔,大於零說明date1比date2晚,反之。。。。
要獲得幾天幾分幾秒的,算算就出來了。
Q:怎麼實現一個登陸頁面,在登陸成功後跳轉到另外一個頁面(我想實現先是一個登陸界面點擊一個登陸按鈕載跳轉到UITabBarController界面怎樣處理啊 )?
A:能夠嘗試下面的方法:
1,在MainWindow.xib裏放入LoginViewController和UITabBarController。
2,Delegate裏application加入下記代碼。
![](http://static.javashuo.com/static/loading.gif)
[window addSubview:tabBarController];
![](http://static.javashuo.com/static/loading.gif)
[window addSubview:loginViewController];
3,Login成功後,在LoginViewController里加入下記代碼。
![](http://static.javashuo.com/static/loading.gif)
[self.view removeFromSuperview];
Q:iPhone中如何實現相似於Timer的定時操做?
A:相似下面代碼實現:
![](http://static.javashuo.com/static/loading.gif)
timer = [NSTimer scheduledTimerWithTimeInterval:(3) target:self selector:@selector (onTimer:) userInfo:nil repeats:YES];
- (
void)onTimer:(NSTimer*)timer {
//處理
![](http://static.javashuo.com/static/loading.gif)
......
![](http://static.javashuo.com/static/loading.gif)
}
Q:UITableViewCell 裏 有個 UITextField當點擊UITextField時會出現軟鍵盤,爲了返回UITextField的值,我在valueChanged事件綁定了 rootViewController 的
-(IBAction) textAction : (id) sender;
但是我同時須要知道該Cell 的 indexPath.row 該怎麼作?
A:有兩種方法:
方法1
先獲取UITextField所在的Cell.
![](http://static.javashuo.com/static/loading.gif)
NSIndexPath *path = [tableView indexPathForCell: (UITableViewCell *) [ (UITextField *)sender superview] ];
方法2
首先,在table loadview 製造cell的時候在cell.tag和textField.tag 設個值
![](http://static.javashuo.com/static/loading.gif)
tmpcell.tag = 3;
![](http://static.javashuo.com/static/loading.gif)
tmpcell.textField.tag = 3;
而後事件啓動的時候這樣
![](http://static.javashuo.com/static/loading.gif)
- (IBAction)textAction:(id)sender
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
NSInteger tag = [sender tag];
![](http://static.javashuo.com/static/loading.gif)
NSIndexPath *indexPath = [self.tableView indexPathForCell: (UITableViewCell *)[self.tableView viewWithTag:tag]];
![](http://static.javashuo.com/static/loading.gif)
[[[rawElementsArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] setValue:[sender text] forKey:
@"value"];
![](http://static.javashuo.com/static/loading.gif)
}
[待續... ...]