我正在尝试创建Plist dictionary
数据的读取并加载到tableview中。在这里,我维护了两个segment
控制按钮和一个tableview
。每当我选择段控制按钮时,我需要加载第一个plist字典数据,然后按钮2加载第二个。我需要区分两个data
集并基于按钮单击它应该重新加载。
我的代码:
// to read data
NSArray *pathse = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = pathse.firstObject;
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"port.plist"];
savedUrl = [[NSMutableDictionary alloc] initWithContentsOfFile: plistPath];
- (IBAction)Click_Segmentbutton:(id)sender {
switch (segment_Button.selectedSegmentIndex) {
case 0:{
break;}
case 1:{
break;}
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSIndexPath *indexPath;
if (indexPath.section == 0)
{
return [[savedUrl objectForKey:@"boysinfo"] count];
}
else
{
return [[savedUrl objectForKey:@"girlsinfo"] count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Here I need to get whenever click the tableview cell selected cell all details
}
答案 0 :(得分:0)
根据我对您的问题的理解,下面是您的目的代码。
<table class="table table-striped responsive-utilities jambo_table" id="myTable">
<thead>
<tr class="headings">
<th>Employee No.</th>
<th>Username</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php $emp='';
foreach($EMPLOYEES as $employee){
if($emp!=$employee->username){ # if username contain duplicate values
?>
<tr>
<td><?php echo $employee->empnum; ?></td>
<td><?php echo $employee->username; ?></td>
<td><?php echo $employee->name; ?> <?php echo $employee->lastname; ?></td>
<td><?php
if ($employee->hasClockOut==1){
echo '<a class="label label-danger">Inactive</a>';
}else {
echo '<a class="label label-success">Active</a>';
}
?></td>
</tr>
<?php }$emp=$employee->username;} ?>
</tbody>
</table>
} //基于索引(选择的段)获取plist文件的函数 - (void)saveDataWithSelectedIndex:(int)index {
//Global
NSMutableDictionary *savedPlistDictionary;
- (void)viewDidLoad {
//Read the plist and save in plistDictionary.
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPathString = paths.firstObject;
NSString *plistNameString = @"second.plist"; //Second plist file
NSString *plistPathString = [documentsPath stringByAppendingPathComponent:plistNameString];
plistDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile: plistPathString];