IOS 自动关闭的Alert窗口

弹出的对话框(UIAlertView)不需要用户点击按钮,可以自动关闭消失,诀窍是利用NSTimer定时器来关闭alertview。

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:[@"一个可以自动关闭的Alert窗口"
                                                   delegate:nil
                                          cancelButtonTitle:nil //NSLocalizedString(@"OK", @"OK")   //取消任何按钮
                                          otherButtonTitles:nil];
    //[alert setBounds:CGRectMake(alert.bounds.origin.x, alert.bounds.origin.y, alert.bounds.size.width, alert.bounds.size.height+30.0)];
    [alert show];
     
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
     
    // Adjust the indicator so it is up a few pixels from the bottom of the alert    
    indicator.center = CGPointMake(alert.bounds.size.width/2,  alert.bounds.size.height-40.0);
    [indicator startAnimating];
    [alert insertSubview:indicator atIndex:0];
    [indicator release];
     
    [NSTimer scheduledTimerWithTimeInterval:3.0f
                                     target:self
                                   selector:@selector(dismissAlert:)
                                   userInfo:[NSDictionary dictionaryWithObjectsAndKeys:alert, @"alert", @"testing ", @"key" ,nil]  //如果不用传递参数,那么可以将此项设置为nil.
                                    repeats:NO];
  
    NSLog(@"release alert");
    [alert release];
  
  
-(void) dismissAlert:(NSTimer *)timer{
     
    NSLog(@"release timer");
    NSLog([[timer userInfo]  objectForKey:@"key"]);
     
    UIAlertView *alert = [[timer userInfo]  objectForKey:@"alert"];
    [alert dismissWithClickedButtonIndex:0 animated:YES];
    
}
  
  
    //定时器停止使用:
  
        [timer invalidate];
        timer = nil;


展开阅读全文

无组件上传图片,窗口自动关闭

08-22

各位兄弟姐妹,小弟碰到一个问题。rnrn就是有个客户反应说,在我们网站,上传图片,点击“上传”会弹出一个窗口,然后他在这个窗口上传图片的时候,上传的过程这个窗口就自动关闭了,然后图片也不上传成功,也没有任何提示。rnrn这个弹出窗口中没有一句话代码是关闭这个窗口的。rnrn小弟用的程序是无组件上传程序。rnrnrn''主程序开始部分rndim formsize,formdata,Msgrnformsize = Request.TotalBytesrnrnIf Formsize > 204800 ThenrnUploadSize=falsernResponse.Write " "rnResponse.EndrnEnd IfrnrnIf Formsize < 600 ThenrnUploadSize=falsernResponse.Write " "rnResponse.EndrnEnd Ifrnrnrnrnformdata = Request.BinaryRead(formsize)rnUploadSize=truernrndim sinfo_Streamrnset Sinfo_Stream = Server.CreateObject("adodb.stream")rnSinfo_Stream.Type = 1 ''2进制流rnSinfo_Stream.Mode = 3 ''读写模式rnSinfo_Stream.OpenrnSinfo_Stream.Write formdata ''保存二进制内容到流对象rn''分离数据变量rndim VbEnterrndim spStr,lenOfspStr,bposrndim loopcnt,exitflag,ppoint,npointrn''保存数据变量 rndim FldData,fldHeadStr,infldposrndim databpos,datalenrndim FldInfo(15,1)rn''fldInfo(0)表单头内容rn''fldInfo(1)表单数据rnrnVbEnter = chrb(13)&chrb(10)''读取第一个VbEnter位置rnbpos = Instrb(formdata,VbEnter)rnSpStr = midb(formdata,1,bpos+1) ''包含了一个0d0arnLenOfspStr = lenb(Spstr) rnppoint = LenOfspStr+1 ''位置指针,指向每一个表单域内容的开始位置rnformdata = midb(formdata,ppoint)rnloopcnt = 0 ''表单元素rndo rn bpos = instrb(formdata,spStr) ''分割位置rn npoint = (ppoint+bpos+lenofspstr-1) ''指向下一表单开始位置rn if bpos < 1 thenrn fldData = midb(formdata,1,instrb(formdata,leftb(spStr,lenOfspstr-2))-1)rn bpos = lenb(fldData)+1rn exitflag = truern elsern FldData = leftb(formdata,bpos-1) rn formdata = midb(formdata,bpos+LenOfspstr)rn end ifrn infldpos = instrb(fldData,vbEnter&vbEnter)rn fldHeadStr = bytes2bstr(midb(fldData,1,infldpos-1))rn fldInfo(loopcnt,0) = fldHeadStr ''表单头rn ''Response.Write fldHeadStr&" "rn databpos = (ppoint+infldpos-1+4)rn Sinfo_Stream.Position = databpos-1rn datalen = (bpos-infldpos-6)rn if datalen = 0 thenrn fldInfo(loopcnt,1) = ""rn elsern fldInfo(loopcnt,1) = Sinfo_Stream.Read(datalen)rn end ifrn ppoint = npointrn loopcnt = loopcnt + 1rnloop until exitflag = truernSinfo_Stream.closernset Sinfo_Stream = Nothingrnrnrn''以上程序数据处理过程rn''处理文件上传开始rnSub SaveData(cs)rnrn filedata = myrequest(cs)rn filesize = lenb(filedata)rn rn if filesize <> 0 then rn filename = GetFileName(cs)rn FileTypeName = GetFileTypeName(FileName)rn If IsvalidFile(FileTypeName)=false Thenrn Response.Write " "rn Response.Endrn Exit Subrn End Ifrn rn rn filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&"."&FileTypeNamern basepath = "../UserDocument/"&goname&"/Picture/"rnrn'===================================================rnset fso =server.CreateObject("Scripting.FileSystemObject")rnIf Fso.folderExists(server.mappath("../UserDocument"))=false ThenrnFso.Createfolder(server.mappath("../UserDocument"))rnend ifrnIf Fso.folderExists(server.mappath("../UserDocument/"&goname&""))=false ThenrnFso.Createfolder(server.mappath("../UserDocument/"&goname&""))rnend ifrnIf Fso.folderExists(server.mappath("../UserDocument/"&goname&"/Picture"))=false ThenrnFso.Createfolder(server.mappath("../UserDocument/"&goname&"/Picture"))rnend ifrnset fso =nothingrnrndim Fstreamrnset FStream = Server.CreateObject("adodb.stream")rnfstream.mode = 3rnfstream.type = 1rnfstream.openrnfstream.position = 0rnfstream.Write filedatarnfstream.savetofile Server.Mappath(basepath&filename),2rnfstream.closernset fstream = nothingrn'============================rn elsern Response.Write " "rn Response.Endrn end ifrnrndim filename1rnfilename1="UserDocument/"&goname&"/Picture/"&filenamern%>rn rnrn<%End Sub rnrnrnSaveData("logo")%>rnrnrn还有一点,我自己的机子测试没有问题,很多客户上传也没有问题,而这个有问题的客户,他说他自己在阿里巴巴和慧聪上传也是没有问题,所以到底是什么我也搞不太清楚了。rnrnrn所以希望大哥大姐能教教我。跪求。rn 论坛

没有更多推荐了,返回首页