[英]Reloading UITableView
我已經閱讀了其他一些文章,但沒有找到適合我的情況的正確解決方案。 我有一個UITableViewController類,該類是從Main App Delegate實例化的,它控制其他視圖,這些視圖被推入從App Delegate創建的UINavigationController實例中。
在UINavigationToolBar上,我有一個UISegmentedControl按鈕,該按鈕分為兩部分,即工廠負載和用戶負載。 我有一個動作方法附加到SegmentedControl上,以檢測何時按下按鈕,並且該方法位於UIViewController類內。 我的目標是讓視圖重新加載由應用程序捆綁包中的plist文件構造的新詞典的內容。 我已經加載了字典,並且要顯示的鍵設置為相應的數據格式,但是當我嘗試重新加載UITableView時,它崩潰了。
這是我嘗試在action方法中使用的最后一個代碼,但仍無法正常工作。
- (void) action:(id)sender {
UISegmentedControl *segment = (UISegmentedControl *) sender;
if ([segment selectedSegmentIndex] == 1)
{
NSLog(@"User Load Selected");
NSString *userLoadFilePath = [[NSBundle mainBundle] pathForResource:@"UserLoads" ofType:@"plist"];
NSDictionary *userLoadDictionary = [[NSDictionary alloc] initWithContentsOfFile:userLoadFilePath];
NSArray *allKeys = [userLoadDictionary allKeys];
keys = allKeys;
dictionary = userLoadDictionary;
[[self tableView] reloadData];
}
else if ([segment selectedSegmentIndex] == 0)
{
NSLog(@"Factory Load Selected");
NSString *factoryLoadFilePath = [[NSBundle mainBundle] pathForResource:@"AlliantPowder" ofType:@"plist"];
NSDictionary *factoryLoadDictionary = [[NSDictionary alloc] initWithContentsOfFile:factoryLoadFilePath];
NSArray *allKeys = [factoryLoadDictionary allKeys];
keys = allKeys;
[[self tableView] reloadData];
}
}
我正在調用[[self tableView] reloadData]
,以嘗試檢索UIViewController中包含的實際表,以嘗試重新加載該表,但沒有運氣。 感謝您的幫助,如果需要更多代碼,請詢問。 謝謝!
安德魯
-------編輯-----------這是參考Chip思想的新代碼。 問題仍然沒有解決,應用仍然崩潰。
- (void) action:(id)sender {
// Create an instance of UISegmentedControl and set it as the sending event.
UISegmentedControl *segment = (UISegmentedControl *) sender;
// Detect which button was pressed and load a new dictionary appropriately
// Checking if userLoads was selected
if ([segment selectedSegmentIndex] == 1)
{
NSLog(@"User Load Selected");
keys = userKeys;
[[self tableView] reloadData];
}
// Checking if factoryLoads was selected
else if ([segment selectedSegmentIndex] == 0)
{
NSLog(@"Factory Load Selected");
keys = [dictionary allKeys];
[[self tableView] reloadData];
}
[segment release];
}
我將預加載字典並將其作為ivars保留在控制器類中。
我敢打賭,字典內容的加載尚未完成,因此實際上是在數據更改時調用reloadData,這導致了崩潰。
同樣,讀取是一個昂貴的選項,每次segementControl更改狀態時您都在加載。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.