Hello there!
Basically, my app displays the title, summary, and the image of the formula. It displays a large amount of information parsed from a local XML file. The XML looks like this:
It is parsed into the following in Rule.h:
Then everything gets displayed into a UITableViewCell :
Everything's dandy with the text. It works out great; summaryView.text = aRule.summary. But what I want to do is display an image from the app's bundle based upon the contents of the <image> tag from a <rule> from the XML file.
I need some way to take the contents of the string aRule.image and get it into a UIImageView or UIImage so I can display the formula. I've tried things like initWithData: but I've gotten nowhere.
Any help would be very appreciated!
Basically, my app displays the title, summary, and the image of the formula. It displays a large amount of information parsed from a local XML file. The XML looks like this:
Code:
<Rule id="1">
<title>Pythagorean Theorem</title>
<summary>Use to find lengths of legs or the hypotenuse of a right triangle</summary>
<image>pythagtheo.png</image>
</Rule>
It is parsed into the following in Rule.h:
Code:
@interface Rule : NSObject {
NSInteger ruleID;
NSString *title;
NSString *summary;
NSString *image;
}
Then everything gets displayed into a UITableViewCell :
Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell= [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
switch(indexPath.section)
{
case 0:
cell.text = @"";
CGRect summaryRect = CGRectMake(3.0, 3.0, 290.0, 190.0);
UITextView *summaryView = [[UITextView alloc] initWithFrame:summaryRect];
summaryView.text = aRule.summary;
summaryView.font = [UIFont systemFontOfSize: 15.0];
summaryView.editable = NO;
[cell.contentView addSubview:summaryView];
[summaryView release];
break;
case 1:
cell.text = @"";
CGRect formulaRect = CGRectMake(10.0, 10.0, 290.0, 190.0);
UIImage *formulaImage = [UIImage imageNamed:@"sif.png"];
UIImageView *formulaView = [[[UIImageView alloc] initWithFrame:formulaRect] initWithImage:formulaImage];
[cell.contentView addSubview:formulaView];
[formulaView release];
[formulaImage release];
break;
}
return cell;
}
- (NSString *)tableView:(UITableView *)tblView titleForHeaderInSection:(NSInteger)section {
NSString *sectionName = nil;
switch(section)
{
case 0:
sectionName = [NSString stringWithString:@"Summary"];
break;
case 1:
sectionName = [NSString stringWithString:@"Formula"];
break;
}
return sectionName;
}
Everything's dandy with the text. It works out great; summaryView.text = aRule.summary. But what I want to do is display an image from the app's bundle based upon the contents of the <image> tag from a <rule> from the XML file.
I need some way to take the contents of the string aRule.image and get it into a UIImageView or UIImage so I can display the formula. I've tried things like initWithData: but I've gotten nowhere.
Any help would be very appreciated!