- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我制作了一个应用程序,以允许用户上传带有附加说明的图像。然后两者都显示在 ScrollView 中。我在图片下方还有一个 UILabel,它应该显示上传用户的详细信息以及上传日期。
但是,目前应该显示用户信息和日期的 UILabel 并没有以我想要的格式(例如“上传者:用户名,日期”)进行显示,而是我获得了以下内容..
下面是用户上传图片时使用的PFObject的代码;
PFObject *imageObject = [PFObject objectWithClassName:@"ReportImageObject"];
[imageObject setObject:file forKey:@"image"];
[imageObject setObject:[PFUser currentUser] forKey:@"user"];
[imageObject setObject:self.descriptionTextField.text forKey:@"comment"];
下面是我将 PFObject 的值分配给 UILabel 的地方;
NSDate *creationDate = reportObject.createdAt;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"HH:mm dd/MM yyyy"];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 210, reportImageView.frame.size.width, 15)];
infoLabel.text = [NSString stringWithFormat:@"Uploaded by: %@, %@", [reportObject objectForKey:KEY_USER], [df stringFromDate:creationDate]];
infoLabel.font = [UIFont fontWithName:@"Arial-ItalicMT" size:9];
infoLabel.textColor = [UIColor blueColor];
infoLabel.backgroundColor = [UIColor clearColor];
[reportImageView addSubview:infoLabel];
术语KEY_USER
定义为@"user"
让我感到困惑的是,我访问 descriptionFieldText.text 的其他标签(图像描述 - 可以在左上角“测试 3”上传的图片上模糊地看到)显示用户输入的内容?即使我在 NSLog
中检查与它关联的 PFObject objectForKey
并且它显示与不需要的 UILabel
相似的格式,但实际的标签访问期望值?
已更新使用的主要方法
显示上传图像的 View Controller - 显示 UILabel 的地方
-(void)getReportImages{
//Fetch images
PFQuery *query = [PFQuery queryWithClassName:@"ReportImageObject"];
[query orderByDescending:KEY_CREATION_DATE];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
if (!error) {
self.reportsObjectArray = nil;
self.reportsObjectArray = [[NSArray alloc] initWithArray:objects];
[self loadReportViews];
} else {
[self showErrorView:error];
}
}];
}
-(void)loadReportViews{
for (id viewToRemove in [self.reportsScroll subviews]) {
if ([viewToRemove isMemberOfClass:[UIView class]])
[viewToRemove removeFromSuperview];
}
int originY = 10;
for (PFObject *reportObject in self.reportsObjectArray){
UIView *reportImageView = [[UIView alloc] initWithFrame:CGRectMake(10, originY, self.view.frame.size.width -20, 300)];
//Adds image
PFFile *image = (PFFile*)[reportObject objectForKey:KEY_IMAGE];
UIImageView *userImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData:image.getData]];
userImage.frame = CGRectMake(0, 0, reportImageView.frame.size.width, 200);
[reportImageView addSubview:userImage];
//Adds image info
NSDate *creationDate = reportObject.createdAt;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"HH:mm dd/MM yyyy"];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 210, reportImageView.frame.size.width, 15)];
infoLabel.text = [NSString stringWithFormat:@"Uploaded by: %@, %@", [reportObject objectForKey:KEY_USER], [df stringFromDate:creationDate]];
infoLabel.font = [UIFont fontWithName:@"Arial-ItalicMT" size:9];
infoLabel.textColor = [UIColor blueColor];
infoLabel.backgroundColor = [UIColor clearColor];
[reportImageView addSubview:infoLabel];
//Adds image description
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 24, reportImageView.frame.size.width, 15)];
descriptionLabel.text = [reportObject objectForKey:KEY_COMMENT];
descriptionLabel.font = [UIFont fontWithName:@"ArialMT" size:13];
descriptionLabel.textColor = [UIColor whiteColor];
descriptionLabel.backgroundColor = [UIColor clearColor];
[reportImageView addSubview:descriptionLabel];
[self.reportsScroll addSubview:reportImageView];
originY = originY + reportImageView.frame.size.width + 20;
NSLog(@"Test of description%@",descriptionLabel);
NSLog(@"The content of infolabel %@", infoLabel);
}
self.reportsScroll.contentSize = CGSizeMake(self.reportsScroll.frame.size.width, originY);
}
用户分配图像和图像描述的 UIViewController也是创建 imageObject 的地方
- (void)sendPressed:(id)sender{
[self.descriptionTextField resignFirstResponder];
self.navigationItem.rightBarButtonItem.enabled = NO;
UIActivityIndicatorView *loadingSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[loadingSpinner setCenter:CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0)];
[loadingSpinner startAnimating];
[self.view addSubview:loadingSpinner];
//Upload a new picture if not currently uploaded.
NSData *pictureData = UIImagePNGRepresentation(self.imageToUpload.image);
PFFile *file = [PFFile fileWithName:@"image" data:pictureData];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
PFObject *imageObject = [PFObject objectWithClassName:@"ReportImageObject"];
[imageObject setObject:file forKey:@"image"];
[imageObject setObject:[PFUser currentUser] forKey:@"user"];
[imageObject setObject:self.descriptionTextField.text forKey:@"comment"];
[imageObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
if (succeeded) {
[self.navigationController popViewControllerAnimated:YES];
}
else {
NSString *errorString = [[error userInfo] objectForKey:@"error"];
UIAlertController *errorAlertView = [UIAlertController alertControllerWithTitle:@"Error" message:errorString preferredStyle:UIAlertControllerStyleAlert];
[errorAlertView addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:errorAlertView animated:YES completion:nil];
}
}];
}
else{
NSString *errorString = [[error userInfo] objectForKey:@"error"];
UIAlertController *errorAlertView = [UIAlertController alertControllerWithTitle:@"Error" message:errorString preferredStyle:UIAlertControllerStyleAlert];
[errorAlertView addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:errorAlertView animated:YES completion:nil];
}
}progressBlock:^(int percentDone) {
NSLog(@"Uploaded: %d %%", percentDone);
}];
}
最佳答案
只需使用用户名而不是整个用户对象
PFUser *user = (PFUser*)[reportObject objectForKey:KEY_USER];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 210, reportImageView.frame.size.width, 15)];
infoLabel.text = [NSString stringWithFormat:@"Uploaded by: %@, %@", user.username, [df stringFromDate:creationDate]];
infoLabel.font = [UIFont fontWithName:@"Arial-ItalicMT" size:9];
infoLabel.textColor = [UIColor blueColor];
infoLabel.backgroundColor = [UIColor clearColor];
[reportImageView addSubview:infoLabel];
PFObject *imageObject = [PFObject objectWithClassName:@"ReportImageObject"];
imageObject[@"image"] = file;
imageObject[@"user"] = [PFUser currentUser];
imageObject[@"comment"] = self.descriptionTextField.text;
关于ios - 将 PFObject 分配给 UILabel - 将 PFUser 转换为 NSString 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45873442/
使用 WSDL2ObjC 我得到了很多类,它们是 NSString 的子类。我发现初始化这些类的任何对象的 NSString 值很麻烦。 假设我的类(class)是这样的: @interface mC
当调用 +[NSURL URLWithString:] 时,我有两个构建 URL 的选项: [[@"http://example.com" stringByAppendingPathComponent
我需要删除字符串末尾的空格。我怎样才能做到这一点?示例:如果字符串是 "Hello " 它必须变成 "Hello" 最佳答案 摘自这里的答案:https://stackoverflow.com/a/5
NSString *test = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 如何将此字符串转换为字节? 最佳答案 NSData *bytes = [test dataUsingEn
我对 NSString 变量有疑问。 .h 文件 NSString *strDeleteFilePath; @property (nonatomic,retain) NSString*
我对这个功能有疑问: - (instancetype)initWithCenter:(CLLocationCoordinate2D)center
如果我有方法 - (void) myMethod:(NSString *)string { [Object anothermethodWithString:string]; } 我打电话 [O
ios 中初始化字符串变量的两种方式有什么区别(,adv/disadv)? NSString *var = @"value" 和 NSString *var =[ [NSString alloc] i
我认为这个问题已经足够清楚了,但仍然 - 有什么区别: NSString *string = @"Hello world!"; 和 NSString *string = [[NSString allo
我正在尝试将 NSString 转换为单个字符。当我写 [[NSLocale] currentLocale] objectForKey:NSLocaleDecimalSeparator] 时,我得到
我有指示制作一个前缀方法,该方法在每个位置采用两个字符串,其中 mask = 0 并且第一个字符串 = 第二个字符串,直到不满足这些条件为止,即您的前缀 NSString。 我做了尝试,但由于某种原因
我有 3 个 NSString 和 1 个带值的 NSArray,我尝试将所有字符串转换为一个: string01 = [string01 stringByAppendingString:[numbe
我有一个包含以下文本的 NSString: You can now download "file.png" from "http://www.example.com/RANDOM.png" 如何使用该
我有一个完整的 URL,比方说 http://www.mywebsite.com//Folder /Detals /Final Image /La Image Logo.jpg 在这个NSString
在某些情况下,我可能有一个包含多个单词的 NSString,其中一些是重复的。我想要做的是采用如下所示的字符串: One Two Three Three Three Two Two Two One O
所以我有一个 NSString,让我们说:NSString *mainString = @"My Name is Andrew (I like computers)";我想从 mainString 中
这是我的职责。首先 println 将正确的散列打印到控制台,但在下一行程序崩溃。你能帮助我吗? func sha256(string: NSString) -> NSString { var
我刚刚看到一行由同事编写的代码,我以前从未在 Obj-C 中见过它。它看起来形式很糟糕,我想更改它,但它似乎有效(应用程序按预期工作),我什至不知道将其更改为什么。 NSString **string
我花了很长时间寻找一种获取 nsstring 对象的匹配计数的方法。但我找不到。如何获取 String_one 和 String_Two 的匹配计数?我需要你的帮助.. NSString *Strin
在我看来,我正在处理的代码应该是这样写的: if (!instructions) { instructions = [[UITextView alloc] init]; ins
我是一名优秀的程序员,十分优秀!