그래서 이것은 내가 지금까지 시도한 것입니다.
사진을 찍는 약간의 코드를 만들었습니다 (중요한 스 니펫 만).
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
self.imageView.image = chosenImage;
_camera_button.hidden = true;
_camera_imageview.hidden = false;
[_next_camera setEnabled:YES];
NSData *imageData = UIImagePNGRepresentation(chosenImage);
[self upload_selfie:imageData];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
그런 다음 버튼을 클릭하면 데이터베이스에 업로드합니다. 이것이 내가 시도한 것입니다.
- (IBAction)upload_selfie:(NSData *)data{
PFFile *imageFile = [PFFile fileWithName:@"Image.png" data:data];
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
// Hide old HUD, show completed HUD (see example for code)
// Create a PFObject around a PFFile and associate it with the current user
PFObject *selfie = [PFObject objectWithClassName:@"selfie1"];
[selfie setObject:imageFile forKey:@"imageFile"];
PFUser *user = [PFUser currentUser];
[selfie setObject:user forKey:@"imageFile"];
[selfie saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
}
else{
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
else{
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
다음 selfie1
과 같이 구문 분석이 이루어집니다.
하지만 오류가 발생합니다. 잡히지 않은 예외 'NSInvalidArgumentException'으로 인해 앱 종료, 이유 : '-[UIButton length] : unrecognized selector sent to instance
이유는 무엇입니까?
중단 점에서 다음 사항을 알 렸습니다.
그리고 이것들은 :
그리고 나는 이것을 발견했습니다.
그리고 이것은 디버깅에서 :
upload_selfie
받는buttonI did a few try. It may need a few works/tests, but: Here could be a solution:
Change:
- (IBAction)upload_selfie:(NSData *)data
To:
- (IBAction)upload_selfie:(id)sender withData:(NSData *)data
{
if ([data isKindOfClass:[NSData class]])
{
//Put the rest of your code, it what would called manually
}
else
{
// User clicked on the button, but didn't "send" data with it.
}
}
Call it with [self upload_selfie:nil withData:imageData];
The question: Why?
If you call an IBAction
method, you'll send with it the sender
.
Remember, we usually write: -(IBAction)actionMethod:(id)sender
. If you want to check the sender, you may do, in case of a UIButton: UIButton *button = (UIButton *)sender;
So, from what I understood, this kind of method will take the first parameter as the sender if it's called from an user interaction (by opposition of a call by code with [self actionMethod:mySender]
.
But a thing I don't understand is why you put it as a IBAction
at first, and seem to link no "direct user action" to it.
편집 :
: 추가 자세한 설명 후, 나는이 좋을 것
@property (nonatomic, strong) NSData *imageDataToSend;
교체 [self upload_selfie:imageData];
와 함께 : [self setImageDataToSend:imageData];
교체 PFFile *imageFile = [PFFile fileWithName:@"Image.png" data:data];
와 함께 : PFFile *imageFile = [PFFile fileWithName:@"Image.png" data:imageDataToSend];
교체 -(IBAction)upload_selfie:(NSData *)data
와 함께 -(IBAction)upload_selfie:(id)sender
또는 -(IBAction)upload_selfie:(UIButton*)button
당신은 매우 혼란스러워 보인다 때문이다.
당신이 추가 할 수 있습니다 무엇 : 넣을 self.imageDataToSend
에 nil
그것의 송신 번. IBAction
그렇지 imageDataToSend
않은 경우 메서드 시작 부분에서 확인하십시오 nil
. 모든 코드가 어떻게 작동하는지 모르겠지만 upload_selfie
사용자가 여러 번 클릭 한 경우 (그리고 같은 이미지를 불필요하게 여러 번 보내면) 버튼 을 클릭하면 비활성화 할 수도 있습니다. 전송이 완료되면 (사용 [button:setEnabled:TRUE/FALSE];
).
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다