English 中文(简体)
从清单中向国家统计局输入数据
原标题:Outputting data to an NSString from a plist

I m 摘录一个清单中的一些数据:

<dict>
<key>Feb 7, 2000</key>
<array>
    <string>7</string>
    <string>8</string>
</array>
<key>Jan 27, 2001</key>
<array>
    <string>8</string>
    <string>7</string>
</array>

并使用以下代码,将数据输入国库:

  NSString * myString = [NSString stringWithFormat:@"%@",self.data];

    myLabel.text = myString;

产出载于<代码>(7,8)。

任何人都知道如何去除母体和 com。 并且将价值观分开,以便我能够展示如下内容:<条码>第一:7秒:8

最佳回答

例:

<dict>
<key>Feb 7, 2000</key>
<array>
    <string>7</string>
    <string>8</string>
</array>
<key>Jan 27, 2001</key>
<array>
    <string>8</string>
    <string>7</string>
</array>
</dict>

法典:

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; 

for(id key in dict) {
    NSLog(@"First:%@ Second:%@", [[dict objectForKey:key] objectAtIndex:0],  [[dict objectForKey:key] objectAtIndex:1]);
}

产出:

First:7 Second:8
First:8 Second:7


EDIT (response to comment)

First you need to determine the keys within the NSMutableDictionary.
Load the .plist file, loop through and add the keys to an NSMutableArray.

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; 
NSMutableArray *keys = [[NSMutableArray alloc] init];
for(id key in dict) [keys addObject:[NSString stringWithFormat:@"%@",key]];

Make sure the array can be accessed by the UIPickerView.
The UIPickerView should be able to retrieve the keys like this:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
    return [keys objectAtIndex:row];
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
    return [keys count];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    return 1;
}

最后,更新<条码>IDLabel>。

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    theLabel.text = [NSString stringWithFormat:@"First:%@ Second:%@", 
                      [[dict objectForKey:[keys objectAtIndex:row]] objectAtIndex:0],  
                      [[dict objectForKey:[keys objectAtIndex:row]] objectAtIndex:1]];
}

http://www.un.org/Depts/DGACM/index_french.htm 现有几行:

Feb 7, 2000
Jan 27, 2001

如选定“Jan 27,2001年”,UILabel:

First:8 Second:7
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签