我创建了一个Xcode应用程序,在这种情况下使用核心数据框架存储用户输入评论(详细信息和评级0-5)。
所以基本上我已经设法创建了一个存储用户输入的视图控制器,然后将其显示在表视图控制器中。
然后,用户可以从表视图控制器中选择他们想要的任何现有评论,然后将其带到新的视图控制器,该控制器显示用户选择的特定评论。
问题是我已设法使用此代码显示字符串值" [self.detailView setText:[self.managedObject valueForKey:@"detail"]];
"但我不能让它显示在核心数据中存储为整数(16)的评级值。
.h详细视图控制器
#import <UIKit/UIKit.h>
#import "reviewTableViewController.h"
#import "reviewViewController.h"
#import "Reviews.h"
@interface reviewDetailViewController : UIViewController <NSFetchedResultsControllerDelegate, UITextFieldDelegate> //adding fetched controller delegate and text field delegate
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) IBOutlet UITextView *detailView; //holds detail values
@property (nonatomic, strong) Reviews *reviews; //property for holding reviews
@property (strong) NSManagedObject *managedObject; //hold core data property
@property (strong, nonatomic) IBOutlet UILabel *ratingView; //holds rating values
@property (strong, nonatomic) IBOutlet UIButton *myButton;
@property (strong, nonatomic) IBOutlet UIButton *myButton1; //buttons for borders
@end
.m详细视图控制器
- (void)viewDidLoad
{
[super viewDidLoad];
_myButton.layer.borderWidth = .5f;
_myButton.layer.borderColor = [[UIColor lightGrayColor]CGColor]; //adding borders for tet displa using buttons, when screen loads
_myButton1.layer.borderWidth = .5f;
_myButton1.layer.borderColor = [[UIColor lightGrayColor]CGColor];
[self.detailView setText:[self.managedObject valueForKey:@"detail"]]; //displaying detail value
//[self.ratingView setText:[self.managedObject valueForKey:@"rating"]];
//[self.ratingView setValue:[NSNumber numberWithInteger:managedObject] forKey:@"rating"];//displaying rating value
//[self.puzzle setValue:[NSNumber numberWithInt:timeTaken] forKey:@"bestTime"];
}
.m表视图控制器
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get a reference to our detail view
// Pass the managed object context to the destination view controller
// [super prepareForSegue:segue sender:sender];
// If we are editing a picture we need to pass some stuff, so check the segue title first
if ([[segue identifier] isEqualToString:@"detailSegue"]) //using segue link name given
{
//Get the row we selected to view
NSManagedObject *managedObjects = [self.reviewsArray objectAtIndex:[[self.tableView indexPathForSelectedRow] row]]; //choosing the selected cell value
reviewDetailViewController *destViewController = segue.destinationViewController;
destViewController.managedObject = managedObjects; //displaying it in the destination controller
}
}
答案 0 :(得分:1)
您需要将整数转换为字符串。
[self.ratingView setText:[NSString stringWithFormat:@"%@", [self.managedObject valueForKey:@"rating"]]];
答案 1 :(得分:1)
NSNumber *x = managedObject.rating; // rating is NSNumber!
int y = x.intValue; // this is how you get an int!
label.text = [NSString stringWithFormat:@"%i", managedObject.rating.intValue];